2012-03-28 86 views
1

嗨,我有以下问题,使用php加载https网站

我想用PHP来安装一个网站。我用CURL,但在我的服务器上,我设置了open_basedir。

所以,我收到以下错误信息:

CURLOPT_FOLLOWLOCATION不能被激活的safe_mode时或open_basedir的是

代码集:

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_USERAGENT, $useragent); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
$store = curl_exec ($ch); 
$error = curl_error ($ch); 
return $store; 

是否有其他办法使用php加载网站?!

感谢

+1

你可能并不需要'CURLOPT_FOLLOWLOCATION'可言。只要删除该行。 – ceejayoz 2012-03-28 17:57:38

+0

您仍然可以使用卷曲,您只需手动执行重定向。 – 2012-03-28 17:59:04

+0

@Brian:只有当特定的网址重定向到实际的内容。不是每个人都使用重定向... – 2012-03-28 17:59:32

回答

2

您可以尝试使用得到了file_get_contents()网站的内容:

$content = file_get_contents('http://www.example.com/'); 

// to specify http headers like `User-Agent`, 
// you could create a context like so: 
$options = array(
    'http' => array(
     'method' => "GET", 
     'header' => "User-Agent: PHP\r\n" 
    ) 
); 
// create context 
$context = stream_context_create($options); 
// open file with the above http headers 
$content = file_get_contents('http://www.example.com/', false, $context); 
+0

有没有办法用file_get_contents设置用户代理? – matthias 2012-03-28 18:24:37

+0

@ user1131623 - 查看示例4,地址为http://www.php.net/manual/en/function.file-get-contents.php – Cyclonecode 2012-03-28 19:57:44