php下通过伪造http头解锁防盗链的代码
发布时间:2023-08-14 11:04:46 所属栏目:PHP教程 来源:
导读:方法一,实例代码如下:
$txt=$_get['url'];
echo referfile($txt,'http://www.Cuoxin.com/');
function referfile($url,$refer='') {
$opt=array('http'=>array('
$txt=$_get['url'];
echo referfile($txt,'http://www.Cuoxin.com/');
function referfile($url,$refer='') {
$opt=array('http'=>array('
方法一,实例代码如下: $txt=$_get['url']; echo referfile($txt,'http://www.Cuoxin.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);//得出header中的get部分 $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的第一行一般是请求文件的状态。具体请参照http 1.1状态代码及其含义 hi.baidu.com/110911/blog/item/21f20d2475af812ed50742c5.html这里是正常的文件请求状态,只需直接转向就可以。其他状态的继续执行程序 header("location:$url"); //开源代码Cuoxin.com die(); } } //302 转向,大部分的防盗链系统都是先判断referfer,对了的话再转向真实的地址。下面就是获取真实的地址。 $arr=explode("n",$tp); $arr1=explode("location: ",$tp);//分解出location后面的真时地址 $arr2=explode("n",$arr1[1]); header('content-type:application/force-download');//强制下载 header("location:".$arr2[0]);//转向目标地址 die(); ?> (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐