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;

php curl 突破防盗链
标签: