Like the files I put on a nano-disk, Http://img.namipan.com/downfile/da333ee178bdad6531d1ec1540cf86277c116b6300887600/02.Paid%20In%20Full.mp3.
This address can not be directly downloaded and can not be played in the Web Player, click to download to a download page. To be able to download the file directly or play it, it is necessary to forge Referfer, spoof the server, Referfer is a link from the nano-disk.
The first approach is to use PHP's built-in function stream_context_create.
The code is as follows:
Copy Code code 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);
}
But this code has a disadvantage, file_get_contents is actually the other server's files read to their own server and then sent to the browser, not only increase the pressure on their own servers, and download the response speed is still very slow, this is not a good solution.
Later looked at the manual, both to reduce the pressure on their own servers, but also to achieve confusion to the other server. You can change the Referfer information in the header.
The revised code is as follows:
Copy Code code as follows:
<?php
$url = "Img.namipan.com/downfile/da333ee178bdad6531d1ec1540cf86277c116b6300887600/02.paid%20in%20full.mp3";/ Here's the URL to filter out http://
$urlarr =explode ("/", $url);
$domain = $urlarr [0];//decomposition of the domain name
$getfile =str_replace ($urlarr [0], ", $url);
$content = @fsockopen ("$domain", $errno, $errstr, 12);//Connect to the other server first
if (! $content) {//cannot link to prompt for error message
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"); forged Referfer
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); Read the header information and it will contain: Location:http://xxx/xxx.mp3, this is the address we want.
}
$arr =explode ("\ n", $TP);
$arr 1=explode ("Location:", $TP);
$arr 2=explode ("\ n", $arr 1[1]);//Decompose location: Back address
Header (' content-type:application/force-download ');
Header ("Location:". $arr 2[0]);
Fclose ($content);
OK, the purpose is reached.
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
attach another paragraph of implementation code:
The most original crack network disk restrictions outside the chain of PHP code, if you want to learn to study can continue to see if you want to get the code directly with the need to improve, this code is for reference only learning.
Creates a new file file.php. The next parameter is the need to forge the Referfer target address bar. such as: File.php/http://www.xxx.xxx/xxx.mp3
Copy 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 on their own
$downfile =str_replace ("", "%20", $url);//replace spaces, etc., can be replaced according to the actual situation
$downfile =str_replace ("http://", "", $downfile);/Remove http://
$urlarr =explode ("/", $downfile);//Break out the domain name by "/"
$domain = $urlarr [0];//domain name
$getfile =str_replace ($urlarr [0], ", $downfile);//Get part of header
$content = @fsockopen ("$domain", $errno, $errstr, 12);//Connect target host
if (! $content) {//link does not prompt for error
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"); 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 explain. The first line of the header is typically the state of the request 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 turn directly on it. Continuing execution of other States
Header ("Location: $url");
Die ();
}
}
302 turn, most of the anti-theft chain system is the first Judge Referfer, the words and then turn to the real address. Here's how to get the real address.
$arr =explode ("\ n", $TP);
$arr 1=explode ("Location:", $TP)//To decompose the real-time address behind the Location
$arr 2=explode ("\ n", $arr 1[1]);
Header (' content-type:application/force-download ');/force download
Header ("Location:". $arr 2[0]);//Turn to Destination address
Die ();
?>
115 screen picture outside the chain test (not I do): Original address: http://u.115.com/file/f3b7c9046
External chain Address: yun_qi_img/02.jpg
115 Network external chain Test 2 (also not I do): http://gg.org.ru/115.php/extraction Code/XXX