方法一,實(shí)例代碼如下:
- $txt=$_get['url'];
- echo referfile($txt,'http://m.survivalescaperooms.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"; //你要訪問(wèn)的域名
- $target = "/test.asp教程"; //你要訪問(wèn)的頁(yè)面地址
- $referer = "http//uuwar.com/"; //偽造來(lái)路頁(yè)面
- $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);
- }
- ?>
其它方法,實(shí)例代碼如下:
- <?php
- $url=str_replace('/file.php/','',$_server["request_uri"]);//得出需要轉(zhuǎn)換的網(wǎng)址。這里我就偷懶,不做安全檢測(cè)了,需要的自己加上去
- $downfile=str_replace(" ","%20",$url);//替換空格之類,可以根據(jù)實(shí)際情況進(jìn)行替換
- $downfile=str_replace("http://","",$downfile);//去掉http://
- $urlarr=explode("/",$downfile);//以"/"分解出域名
- $domain=$urlarr[0];//域名
- $getfile=str_replace($urlarr[0],'',$downfile);//得出header中的get部分
- $content = @fsockopen("$domain", 80, $errno, $errstr, 12);//連接目標(biāo)主機(jī)
- if (!$content){//鏈接不上就提示錯(cuò)誤
- die("對(duì)不起,無(wú)法連接上 $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")){ //這里要說(shuō)明一下。header的第一行一般是請(qǐng)求文件的狀態(tài)。具體請(qǐng)參照http 1.1狀態(tài)代碼及其含義 hi.baidu.com/110911/blog/item/21f20d2475af812ed50742c5.html這里是正常的文件請(qǐng)求狀態(tài),只需直接轉(zhuǎn)向就可以。其他狀態(tài)的繼續(xù)執(zhí)行程序
- header("location:$url"); //開(kāi)源代碼Vevb.com
- die();
- }
- }
- //302 轉(zhuǎn)向,大部分的防盜鏈系統(tǒng)都是先判斷referfer,對(duì)了的話再轉(zhuǎn)向真實(shí)的地址。下面就是獲取真實(shí)的地址。
- $arr=explode("n",$tp);
- $arr1=explode("location: ",$tp);//分解出location后面的真時(shí)地址
- $arr2=explode("n",$arr1[1]);
- header('content-type:application/force-download');//強(qiáng)制下載
- header("location:".$arr2[0]);//轉(zhuǎn)向目標(biāo)地址
- die();
- ?>
|
新聞熱點(diǎn)
疑難解答