php curl 突破防盗链

dafenqi
2023-08-07 / 0 评论 / 32 阅读 / 正在检测是否收录...

php curl 突破防盗链

<?php
$img=$_GET['img'];
function fetch_urlpage_contents($url){
$ch = curl_init();

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);

curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 1000);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 1000);
curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:110.80.7.42', 'CLIENT-IP:110.80.7.42')); //构造IP
curl_setopt($ch, CURLOPT_REFERER, "http://www.baidu.com/"); //构造来路
//curl_setopt($ch, CURLOPT_HEADER, 1);
$file_contents = curl_exec($ch);

$imgurl=str_replace("http://","",$url);
$imgurl=str_replace("/","-",$imgurl);


$fp = fopen('imgs/'.$imgurl, 'w');
fwrite($fp,$file_contents);
fclose($fp);


header("Location:imgs/$imgurl");
curl_close($ch);
return $file_contents;

}

$urls='http://img1.xxxxxx.com/'.$img;

$haha=fetch_urlpage_contents($urls);

 

 

//echo $haha;
0

Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /www/wwwroot/testblog.58heshihu.com/var/Widget/Archive.php on line 1032

评论 (0)

取消