Generally, the domestic network disk is used to control traffic, and the file outer links in the network disk are prohibited. The links to files in the network disk are generally transferred to a special download page, which must be used to download files. For example, the file http://img.namipan.com/downfile/da333ee178bdad6531d1ec1540cf86277c116b6300887600/02.Paid%20In%20Full.mp3 I put in the disk
This address cannot be downloaded directly or played in the webpage player. click download to go to a download page. To download or play this file directly, it is necessary to forge a referfer and cheat the server. referfer is a link from the Nano disk.
The initial method is to use the PHP built-in function stream_context_create.
The code is as follows:
The code is as follows:
Function referfile ($ url, $ refer = "){
$ Opt = array ('http' => array ('header' => "Referer: $ refer "));
$ Context = stream_context_create ($ opt );
Return file_get_contents ($ url, false, $ context );
}
However, this code has a disadvantage. file_get_contents actually reads the files from the other server to its own server and sends them to the browser, which not only increases the pressure on its own server, but also slows down the download response, this is not a good solution.
Later, I read the manual to relieve the pressure on my server and confuse the other server. Modify the referer information in the header.
The code after the revision is as follows:
The code is as follows:
$ Url = "success"; // The url here needs to filter out http ://
$ Urlarr = explode ("/", $ url );
$ Domain = $ urlarr [0]; // break down the domain name
$ Getfile = str_replace ($ urlarr [0], ", $ url );
$ Content = @ fsockopen ("$ domain", 80, $ errno, $ errstr, 12); // connect to the server of the other party first
If (! $ Content) {// The error message is displayed if the link is unavailable.
Die ("Sorry, unable to connect to $ domain. ");
}
Fputs ($ content, "GET $ getfile HTTP/1.0 \ r \ n ");
Fputs ($ content, "Host: $ domain \ r \ n ");
Fputs ($ content, "Referer: $ domain \ r \ n"); // counterfeit referfer
Fputs ($ content, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) \ r \ n ");
While (! Feof ($ content )){
$ Tp. = fgets ($ content, 128); read the header information, which will include Location: http: // xxx/xxx.mp3. what we need is this address.
}
$ Arr = explode ("\ n", $ tp );
$ Arr1 = explode ("Location:", $ tp );
$ Arr2 = explode ("\ n", $ arr1 [1]); // break down Location: the address following
Header ('content-Type: application/force-download ');
Header ("location:". $ arr2 [0]);
Fclose ($ content );
OK.
This original address: http://img.namipan.com/downfile/3a7c64518d46d986283eab73175a8b119305a76480b89200/Equilibrium-Turis_Fratyr-02-Wingthors_Hammer.mp3
After conversion:
Http://mms.music.krmcn.com/mms.music/namipan/img ~~ /3a7c64518d46d986283eab73175a8b119305a76480b89200/Equilibrium-Turis_Fratyr-02-Wingthors_Hammer.mp3
The following code is provided:
The most primitive php code used to crack the restriction on the outer link of the network disk. if you want to study the code, you can continue to read it. if you want to use the code directly, you need to improve it. this code is for reference only.
Create a file. php. The following parameter is the target address of the referer to be forged. Such as: file. php/http://www.xxx.xxx/xxx.mp3
The code is as follows:
$ Url = str_replace ('/file. php/', '', $ _ SERVER [" REQUEST_URI "]); // Obtain the url to be converted. I am so lazy here that I don't need to perform security detection. I need to add it myself.
$ Downfile = str_replace ("", "% 20", $ url); // replace spaces and so on, which can be replaced according to the actual situation
$ Downfile = str_replace ("http: //", "", $ downfile); // remove http ://
$ Urlarr = explode ("/", $ downfile); // break down 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) {// An error is prompted if the link is not connected.
Die ("Sorry, unable to connect to $ domain. ");
}
Fputs ($ content, "GET $ getfile HTTP/1.0 \ r \ n ");
Fputs ($ content, "Host: $ domain \ r \ n ");
Fputs ($ content, "Referer: $ domain \ r \ n"); // counterfeit part
Fputs ($ content, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) \ r \ n ");
While (! Feof ($ content )){
$ Tp. = fgets ($ content, 128 );
If (strstr ($ tp, "200 OK") {// Here we will describe it. The first line of the header is generally the status of the request file. For details, refer to the HTTP 1.1 Status Code and its meaning hi.baidu.com/110911/blog/item/21f20d2475af812ed50742c5.html. this is the normal file request status, and you only need to switch directly. Programs in other states
Header ("Location: $ url ");
Die ();
}
}
// 302 redirection. most anti-Leech systems first judge the referer. If yes, they will then turn to the real address. The following describes how to obtain the real address.
$ Arr = explode ("\ n", $ tp );
$ Arr1 = explode ("Location:", $ tp); // returns the actual address after the Location
$ Arr2 = explode ("\ n", $ arr1 [1]);
Header ('content-Type: application/force-download'); // force download
Header ("location:". $ arr2 [0]); // redirects to the target address
Die ();
?>
115 net disk picture external chain Test (not I do): Original address: http://u.115.com/file/f3b7c9046
External link: http://115.pp.ru/f3b7c9046/02.jpg
115 Test the external link of the network disk 2 (which I did not do): http://gg.org.ru/115.php/extraction code /xxx