Php gets the browser address and then anti-Leech. after refreshing, the address cannot be obtained. what is the problem? & nbsp; my x. php code is as follows. This code indicates that I use a website to reference resources of another website. My website is www.123.com and www.abc.com. if I enter www.123.comx.phplove;, php gets the browser address, then anti-Leech, and the address cannot be obtained after refreshing, what is the problem?
My x. php code is as follows. This code indicates that I use a website to reference resources of another website.
My website is http://www.123.com and http://www.abc.com
If I enter http://www.123.com/x.php/love.mp3, open
Http://www.abc.com/abc/love.mp3. The following code can be fully implemented.
++ ++
Header ("content-Type: text/html; charset = Utf-8 ");
$ SERVER = $ _ SERVER ["REQUEST_URI"];
Preg_match ("/php \/([\ s \ S] +) \. mp3/", $ SERVER, $ url );
$ Urlname = $ url [1];
$ Downurl = 'http: // www.abc.com/abc/'.w.urlname.'.mp3 ';
Header ("location: $ downurl ");
?>
++ ++
Players in web pages can play http://www.123.com/x.php/love.mp3 normally
Later, I added anti-Leech to prevent downloading. Code:
++ ++
Header ("content-Type: text/html; charset = Utf-8 ");
$ SERVER = $ _ SERVER ["REQUEST_URI"];
Preg_match ("/php \/([\ s \ S] +) \. mp3/", $ SERVER, $ url );
$ Urlname = $ url [1];
$ Downurl = 'http: // www.abc.com/abc/'.w.urlname.'.mp3 ';
$ Url = $ _ SERVER ["HTTP_REFERER"]; // obtain the complete URL
$ Str = str_replace ("http: //", "", $ url); // remove http ://
$ Strdomain = explode ("/", $ str); // split it into an array "/"
$ Domain = $ strdomain [0]; // take the first character before "/"
If ($ domain = "www.123.com "){
Header ("location: $ downurl ");
}
If ($ domain = ""){
Header ("location: http://www.123.com/daolian.mp3 ");
}
If ($ domain! = "Www.123.com "){
Header ("location: http://www.123.com/daolian.mp3 ");
}
?>
++ ++
After the modification is complete, anti-Leech protection is implemented. the player playing the video on the webpage is unavailable at http://www.123.com/x.php/love.mp3.
Share:
------ Solution --------------------
First, check what $ _ SERVER ["HTTP_REFERER"] is.
It is unreliable to use HTTP_REFERER.
------ Solution --------------------
The simplest thing is to send an encrypted message, for example, http://www.123.com/x.php/love.mp3. now it is changed to http://www.123.com/x.php/love? Secret = xxxxxxxxx
This secret is generated according to certain rules. it is difficult to forge external sites, and you can verify whether this secret is played on your site.