<?php//突破防盗链的显示图片标签[simg],PHP程序部分
ob_start();
$img=$_GET['url'];
$host=$path=str_replace('http://','',$img);
$host=explode('/',$host);
$host=$host[0];
$path=strstr($path,'/');
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if ($fp)
{
@fputs($fp, "GET $path HTTP/1.1rn");
@fputs($fp, "Host: $hostrn");
@fputs($fp, "Accept: */*rn");
@fputs($fp, "Referer: http://$host/rn");
@fputs($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)rn");
@fputs($fp, "Connection: Closernrn");
}
$Content = '';
while ($str = fread($fp, 4096))
$Content .= $str;
@fclose($fp);
$pos=strpos($Content,"rnrn");
$head=substr($Content,0,$pos);
$text=substr($Content,$pos+4);
header($head);
echo $text;
?>
<?php
//PHP
$url=$_GET['url'];
$ext=pathinfo($url,PATHINFO_EXTENSION);
if($ext!='jpg' && $ext!='gif'){ // 只支持jpg和gif
readfile('http://www.mayday.net.cn/cert/logo.gif');
exit;
}
$file=md5($url).'.'.$ext;
if(file_exists($file)){
readfile($file);
exit;
}else{
$data=file_get_contents($url);
if(!$data){ // 读取失败
readfile('http://www.mayday.net.cn/cert/logo.gif');
exit;
}
$handle=fopen($file,'wb');
fwrite($handle,$data);
fclose($handle);
echo $data;
}
?>