GoDaddy的PHP cURL SSL问题:SSL证书问题:无法获取本地颁发者证书

时间:2019-07-04 20:06:49

标签: php ssl curl

我遇到了来自GoDaddy的新SSL证书的问题,这是我的代码:

<?php
$url = "https://myurl.com";
$ch = curl_init($url);

$certificate_location = "ca-bundle.crt"; // modify this line accordingly (may need to be absolute)
curl_setopt($ch, CURLOPT_CAINFO, $certificate_location);
curl_setopt($ch, CURLOPT_CAPATH, $certificate_location);

curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);

$result = curl_exec($ch);
$errtext = curl_error($ch);
$errnum = curl_errno($ch);

var_dump($result);
var_dump($errtext);
var_dump($errnum);

这将导致error 60的{​​{1}}

我尝试抓住latest CA certificates extracted from Mozilla并指向cURL来使用它,但是没有任何效果。有什么想法吗?

1 个答案:

答案 0 :(得分:-1)

替换下面的curl调用行

curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,TRUE);

收件人

curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,FALSE);

CURLOPT_SSL_VERIFYPEER:此选项告诉cURL验证服务器上SSL证书的真实性。

如果您想验证同伴,则

1)在Apache中启用mod_ssl,在php.ini中启用php_openssl.dll 2)在路径为php.ini的文件中添加证书的这些行:

curl.cainfo =“ yourpath / cacert.pem” openssl.cafile =“ yourpath / cacert.pem”

3)并重新启动服务器。