Home > Backend Development > PHP Tutorial > PHP fake referer example code_PHP tutorial

PHP fake referer example code_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:49:25
Original
719 people have browsed it

The complete program will be given directly here. You can modify it yourself for specific applications.
The example I give 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 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 whatever 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);//Replace with "/" 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, unable to 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 programs in other states

header("Location:$url");
die();
}
}

//302 redirection, most The anti-hotlinking system first determines the referrer, and then switches to the real address if it is correct. The following is to obtain the real address.
$arr=explode("n",$tp);
$arr1=explode("Location: ",$tp);//Decompose the real-time address after 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 use other special methods for the anti-hotlinking system that uses referer to determine whether it is a hotlink. For anti-hotlinking, this probably won’t apply.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319547.htmlTechArticleThe complete program is given directly here. The specific application can be modified by yourself. The example I give here is very simple. In fact, many applications can be developed from this example. For example...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template