<?php
function GetHttpPage($HttpUrl)
{
$opts=array(
'http'=>array(
'method'=>"GET",
'header'=>"User-Agent: Baiduspider+(+http://www.baidu.com/search/spider.htm)\r\n"
)
);
$context=stream_context_create($opts);
$result=@file_get_contents($HttpUrl,false,$context);
}
echo GetHttpPage("http://127.0.0.1/");
?>iis+php环境下 测试成功
http头读取显示 HTTP_HOST:127.0.0.1 HTTP_USER_AGENT:Baiduspider+(+http://www.baidu.com/search/spider.htm) apache+php(国外空间)环境下 测试失败
http头读取显示 HTTP_ACCEPT:*/* HTTP_HOST:127.0.0.1 HTTP_USER_AGENT:PHP/5.2.17