需要阅读https网页,但我的网络服务器不支持https包装

时间:2010-11-20 21:34:49

标签: php curl https

我需要使用php通过这个简单的命令来阅读网页的内容:

$pagina='https://graph.facebook.com/me?access_token=' . $cookie['access_token'];
$user = json_decode(file_get_contents($pagina));

正如您所看到的,协议是https。当我执行这些命令时,我总是得到:

  

[function.file-get-contents]:失败   打开流:

在stackoverflow的其他答案中,一些用户建议使用此代码:

$w = stream_get_wrappers();
echo 'openssl: ',  extension_loaded  ('openssl') ? 'yes':'no', "\n";
echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n";
echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n";
echo 'wrappers: ', var_dump($w);

为了知道我的服务器是否有https包装器,结果为否。

那么,任何想法如何使用PHP来检索这个https页面?也许用CURL任何示例代码?非常感谢!

1 个答案:

答案 0 :(得分:2)

Https网站使用curl

<?php
$url = "https://www.google.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>