Referer PHP Forged Referer Instance Code

Source: Internet
Author: User
Here directly to the complete program, the specific application can be modified by themselves.
The example I gave here is very simple, and in fact, there are many applications that can be developed from this example. such as hiding the real URL address ... Hey, I'm going to do the exact analysis.
Create a new file file.php here. The next parameter is the target address of the referfer that needs to be forged. such as: File.php/http://www.xxx.xxx/xxx.mp3

Copy the Code code as follows:


$url =str_replace ('/file.php/', ' ', $_server[' Request_uri "]);//Get the URL that needs to be converted. Here I am lazy, do not do safety test, need to add up
$downfile =str_replace ("", "%20", $url);//replace spaces, etc., can be replaced according to the actual situation
$downfile =str_replace ("http://", "", $downfile);
$urlarr =explode ("/", $downfile);//split the domain name with "/"
$domain = $urlarr [0];//domain name
$getfile =str_replace ($urlarr [0], ", $downfile);//Get part of the header
$content = @fsockopen ("$domain", $errno, $errstr, 12);//Connect the target host
if (! $content) {//link not on the prompt error
Die ("Sorry, unable to connect on $domain. ");
}
Fputs ($content, "GET $getfile http/1.0\r\n");
Fputs ($content, "Host: $domain \ r \ n");
Fputs ($content, "Referer: $domain \ r \ n");//Forged part
Fputs ($content, "user-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) \r\n\r\n ");
while (!feof ($content)) {
$tp. =fgets ($content, 128);
if (Strstr ($TP, "OK")) {//here to illustrate. The first line of the header is typically the state of the requested file. Please refer to the HTTP 1.1 status code and its meaning hi.baidu.com/110911/blog/item/21f20d2475af812ed50742c5.html here is the normal file request status, just a direct turn on it. Continuation program for other states
Header ("Location: $url");
Die ();
}
}
302 turn, most of the anti-theft chain system is the first to judge the Referfer, the words then turn to the real address. Here's how to get the real address.
$arr =explode ("\ n", $TP);
$arr 1=explode ("Location:", $TP);//Break out the real-time address at the back of
$arr 2=explode ("\ n", $arr 1[1]);
Header (' content-type:application/force-download ');//Forced download
Header ("Location:". $arr 2[0]);//Turn to Destination address
Die ();
?>


This procedure only for use Referer to determine whether hotlinking anti-theft chain system, the use of other special methods of anti-theft chain, this estimate does not apply

The above describes the Referer PHP forged referer instance code, including the referer aspect of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.