2012-03-28 85 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