$uinfo =
parse_url($url);//解析URL地址,比如http://php100.com/archives/1.html
if($uinfo['path']) //
$data =
$uinfo['path'];//这里得到/archives/1.html
else
$data =
'/';//默认根
if(!$fsp = @fsockopen($uinfo['host'], (($uinfo['port']) ?
$uinfo['port'] : "80"), $errno, $errstr, 12)){
echo
"对不起对方网站暂时无法打开,请您稍后访问:".$uinfo['host']; exit;
}else{
fputs($fsp, "GET “.$data .”
HTTP/1.0rn");//如果是跨站POST提交,可使用POST方法
fputs($fsp, "Host: ".$uinfo['host']."rn");
fputs($fsp, "Referer: php100.comrn");//伪造REFERER地址
fputs($fsp, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows
NT 5.1)rnrn");
$res='';
while(!feof($fsp)) {
$res.=fgets($fsp, 128);
if(strstr($res,"200 OK")) {
header("Location:$url"); exit;
}
}
}
//如果是301或302状态码可以继续处理
//返回地址大概形式:HTTP/1.1 301 Moved PermanentlynContent-Length:
164nContent-Type: text/htmlnLocation: http://php100.com/
$arr=explode("n",$res);
$arr=explode(": ",$arr[3]);//Location后面是真实重定向地址
header("location:".$arr[0]);//跳转目标地址
exit;