2017-04-06 32 views
0

當我嘗試使用cURL獲取源代碼時,它不會在$ data中返回任何內容。但是file_get_contents工作正常。我嘗試添加USERAGENT,但結果相同。這是我的代碼:在PHP中使用cURL獲取Github源代碼

$url = "https://github.com/login"; 

$handle = curl_init($url); 
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); 

$data = curl_exec($handle); 
//$data = file_get_contents($url); 

echo $data; 

但我需要通過cURL獲取源代碼。我怎樣才能做到這一點 ?

+0

你想下載完整的源文件或想獲得單個文件的內容。 –

+0

我想獲得完整的源代碼。 @SahilGulati – prokawsar

回答

1

其實SSL問題存在問題。

我總是讓虛假的curl_exec($handle);爲此,我用這個代碼

if (FALSE === $data) 
    throw new Exception(curl_error($handle), curl_errno($handle)); 

調試。然後返回此消息:

Fatal error: Uncaught Exception: SSL certificate problem: unable to get local issuer certificate in . .

然後我加入這行

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

及其工作現在罰款。