referer PHP fake referer example code
The complete program will be given directly here. You can modify it yourself for specific applications.
The example I gave here is very simple. In fact, many applications can be developed from this example. For example, hiding the real URL address... Hehe, just analyze it yourself
Create a new file file.php here. The following parameter is the target address of the referfer that needs to be forged. For example: file.php/http://www.xxx.xxx/xxx.mp3
Copy the code The code is as follows:
$url=str_replace('/file.php/', '',$_SERVER["REQUEST_URI"]);//Get the URL that needs to be converted. I'm being lazy here and don't do security checks. I'll add what I need
$downfile=str_replace(" ","%20",$url);//Replace spaces and the like, you can replace them according to the actual situation
$downfile =str_replace("http://","",$downfile);//Remove http://
$urlarr=explode("/",$downfile);//Use "/" to decompose the domain name
$domain =$urlarr[0];//Domain name
$getfile=str_replace($urlarr[0],'',$downfile);//Get the GET part in the header
$content = @fsockopen("$domain", 80, $errno, $errstr, 12);//Connect to the target host
if (!$content){//If the link cannot be connected, an error will be prompted
die("Sorry, cannot connect to $domain.");
}
fputs($content, "GET $getfile HTTP/1.0rn");
fputs($content, "Host: $domainrn");
fputs($content, "Referer: $domainrn");//Fake part
fputs ($content, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)rnrn");
while (!feof($content)) {
$tp.=fgets($content, 128);
if (strstr($tp,"200 OK")){ //Something to explain here. The first line of the header is generally the status of the requested file. For details, please refer to HTTP 1.1 status codes and their meanings hi.baidu.com/110911/blog/item/21f20d2475af812ed50742c5.html This is the normal file request status, just redirect it directly. Continue executing the program in other states
header("Location:$url");
die();
}
}
//302 redirection, most anti-hotlink systems first determine the referfer, and then redirect to the real one if it is correct the address of. The following is to obtain the real address.
$arr=explode("n",$tp);
$arr1=explode("Location: ",$tp);//Decompose the real-time address behind Location
$arr2=explode("n",$ arr1[1]);
header('Content-Type:application/force-download');//Force download
header("location:".$arr2[0]);//Redirect to the target address
die() ;
?>
This program can only be used for the anti-hotlinking system that uses referer to determine whether it is hotlinking. If other special methods are used to prevent hotlinking, this estimate will not apply.
The above introduces the referer PHP fake referer example code, including the referer content. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.
