Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Google reCaptcha 2.0不起作用,是用于curl的吗?_Php_Recaptcha - Fatal编程技术网

Php Google reCaptcha 2.0不起作用,是用于curl的吗?

Php Google reCaptcha 2.0不起作用,是用于curl的吗?,php,recaptcha,Php,Recaptcha,经过几次尝试(显式渲染),我终于在我的网站上显示了reCaptcha 内部标记 <script src="https://www.google.com/recaptcha/api.js" async defer></script> 我的getCurlData.php代码如下 <?php function getCurlData($url){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); cu

经过几次尝试(显式渲染),我终于在我的网站上显示了
reCaptcha

内部
标记

<script src="https://www.google.com/recaptcha/api.js" async defer></script>
我的
getCurlData.php
代码如下

<?php
function getCurlData($url){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 120);
$curlData = curl_exec($curl);
curl_close($curl);
return $curlData;
}
?>
而不是

getCurlData($url);
问题解决了。不过,我要提出我的问题


那么是否不需要
curl
我们为什么要在
reCaptcha
中使用
curl

它不起作用的原因是您试图访问HTTPS。您不应该使用的解决方案是:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CAINFO, 'cacert.pem');
您应该使用以下解决方案:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CAINFO, 'cacert.pem');

有一个到最新cacert.pem的链接。

而不是
getCurlData()
尝试
file\u get\u contents()
看看会发生什么。谢谢@Stretch,它成功了。您可以看到我的更新。只有在php ini文件中将allow\u url\u fopen设置为1时,文件\u get\u contents()才会工作。通常,您无法更改live服务器上的php ini文件,因为您使用的是共享主机。在这种情况下,你可以依靠旋度。
curl_setopt($ch, CURLOPT_CAINFO, 'cacert.pem');