在浏览器中访问https站点的PHP脚本

时间:2014-02-19 01:28:08

标签: php curl https

我刚开始学习如何使用PHP脚本,我正在尝试访问一个https网站,但php网站上的示例代码似乎没有用。我的php启用了curl和ssl。任何见解都会受到欢迎!谢谢!

<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://www.facebook.com");
curl_setopt($ch, CURLOPT_HEADER, 0);

//grab url and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
?>

1 个答案:

答案 0 :(得分:0)

您需要在访问HTTPs网址时将此 cURL 参数添加到现有集合中。

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

来自文档...

  

设置CURLOPT_SSL_VERIFYPEER,FALSE停止cURL验证对等方的   证书。

<强> EDIT :

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.facebook.com");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$resp=curl_exec($ch);
echo($resp);// <----------------- You will be taken to facebook page.
curl_close($ch);