Php gets the browser address and then anti-Leech. after refreshing, the address cannot be obtained. what is the problem?-php Tutorial

Source: Internet
Author: User
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 input www.123.comx.phplove;, in fact, php gets the browser address and then anti-Leech, and cannot get the address 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.

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.