Like the papers I put on the nano-disk, Http://img.namipan.com/downfile/da333ee178bdad6531d1ec1540cf86277c116b6300887600/02.Paid%20In%20Full.mp3.
This address can not be downloaded directly or played in the Web Player, click the download to go to a download page. To be able to download this file directly or to play this file, it is necessary to forge Referfer, deceive 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:
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 drawback, file_get_contents in fact, the other server's file read to their own server and then sent to the browser, not only to increase their own server pressure, and download reaction speed is very slow, this is not a good solution.
Later read the manual, both to alleviate their own server pressure, but also to confuse the other server. Modify the Referfer information in the header.
The revised code is as follows:
$url = "img.namipan.com/downfile/da333ee178bdad6531d1ec1540cf86277c116b6300887600/02.paid%20in%20full.mp3″;// The URL here is 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 on $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, it will contain: Location:http://xxx/xxx.mp3, we want this address.
}
$arr =explode ("\ n", $TP);
$arr 1=explode ("Location:", $TP);
$arr 2=explode ("\ n", $arr 1[1]);//Break Out location: the back Address
Header (' content-type:application/force-download ');
Header ("Location:". $arr 2[0]);
Fclose ($content);
OK, the purpose is achieved.
This is the 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
http://www.bkjia.com/PHPjc/319077.html www.bkjia.com true http://www.bkjia.com/PHPjc/319077.html techarticle like the papers I put on the nano-disk, http://img.namipan.com/downfile/da333ee178bdad6531d1ec1540cf86277c116b6300887600/02.Paid%20In%. 20full.mp3 This address can not be downloaded directly or in the network ...