php下通过伪造http头破解防盗链的代码
方法一,实例代码如下:
- $txt=$_get['url'];
- echo referfile($txt,'http://www.phpfensi.com/');
-
- function referfile($url,$refer='') {
- $opt=array('http'=>array('header'=>"referer:$refer"));
- $context=stream_context_create($opt);
- header("location:".$url);
- return file_get_contents($url,false,$context);
- }
-
-
- <?php
- $host = "pakey.net";
- $target = "/test.asp教程";
- $referer = "http//uuwar.com/"; //伪造来路页面
- $fp = fsockopen($host, 80, $errno, $errstr, 30);
- if(!$fp){
- echo "$errstr($errno)<br /> ";
- }else{
- $out = "
- get $target http/1.1
- host: $host
- referer: $referer
- connection: close ";
-
- fwrite($fp, $out);
- while(!feof($fp)){
- echo fgets($fp, 1024);
- }
- fclose($fp);
- }
- ?>
其它方法,实例代码如下:
- <?php
- $url=str_replace('/file.php/','',$_server["request_uri"]);
- $downfile=str_replace(" ","%20",$url);
- $downfile=str_replace("http://","",$downfile);//去掉http://
- $urlarr=explode("/",$downfile);
- $domain=$urlarr[0];
- $getfile=str_replace($urlarr[0],'',$downfile);
- $content = @fsockopen("$domain", 80, $errno, $errstr, 12);
- if (!$content){
- die("对不起,无法连接上 $domain 。");
- }
- fputs($content, "get $getfile http/1.0rn");
- fputs($content, "host: $domainrn");
- fputs($content, "referer: $domainrn");
- fputs($content, "user-agent: mozilla/4.0 (compatible; msie 6.0; windows nt 5.1)rnrn");
- while (!feof($content)) {
- $tp.=fgets($content, 128);
- if (strstr($tp,"200 ok")){
- header("location:$url");
- die();
- }
- }
-
- $arr=explode("n",$tp);
- $arr1=explode("location: ",$tp);
- $arr2=explode("n",$arr1[1]);
- header('content-type:application/force-download');
- header("location:".$arr2[0]);
- die();
- ?>
|