程序没问题,能得到网页内容并输出。
有可能是你的 xxx.php 没有重定向成功。
如果在Linux下,可以先用
wget http://www.xxx.com/xxx.php
看看有没有输出想要的结果。
我用来测试的 xxx.php
function redirect($url)
{
if(headers_sent()) {
return false;
}
if(substr($url, 0, 4) != 'http') {
$schema = $_SERVER['SERVER_PORT'] == '443' ? 'https' : 'http';
$host = strlen($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$url = "$schema://$host$to";
}
header("HTTP/1.1 301 Moved Permanently");
header("Location: $url");
exit();
}
redirect('http://google.com/');
我的怎么就行呢。。
************http://localhost/020space/test.php*****
//phpinfo()
$url = "http://localhost/020space/test2.php";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
$rs = curl_exec($curl);
echo "runing curl...";
var_dump($rs);
?>
************http://localhost/020space/test2.php*****
$url = "http://www.hao123.com";
if (!empty($url))
{
Header("HTTP/1.1 303 See Other"); //这条语句可以不写
Header("Location: $url");
}
?>
$url has content....
************显示结果*****
runing curl...string(30645) "(然后是hao123.com的内容,不过貌似没有加载到CSS。。)