对于https用file_get_contents时
PHP Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?
解决方案:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
你可以从语义上看出,它是忽略/跳过了SSL安全验证。也许这不是一个很好的做法,但对于普通的场景中,这几经足够了。
下面是利用Curl
封装的一个能访问HTTPS内容的函数:
function getHTTPS($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $result = curl_exec($ch); curl_close($ch); return $result; }
转载自:http://www.techug.com/php-https