我试图在php中使用reCaptcha v2.0,在服务器验证中我使用此代码:
if(isset($_POST['Direccion_Email']) AND ($_POST['enviar'])) {
if(isset($_POST['g-recaptcha-response'])){
$mensaje_error = "";
include 'config-formulario.php';
require_once __DIR__ . '/recaptcha-master/src/autoload.php';
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if (!$resp->isSuccess()) {
$mensaje_error .= "Control Anti SPAM no es válido <br />";
$errors = $resp->getErrorCodes();
} else {
//DO SOMETHING;
}
但是当我尝试发送一个简单的联系我表格,其中包含姓名,电子邮件和评论时,它会返回此警告:
警告:file_get_contents():SSL操作失败,代码为1. OpenSSL错误消息:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败/ home / diego / www / systec / scripts / recaptcha-master / src /第68行的ReCaptcha / RequestMethod / Post.php
警告:file_get_contents():无法在第68行的/home/diego/www/systec/scripts/recaptcha-master/src/ReCaptcha/RequestMethod/Post.php中启用加密
警告:file_get_contents(https://www.google.com/recaptcha/api/siteverify):无法打开流:第68行/home/diego/www/systec/scripts/recaptcha-master/src/ReCaptcha/RequestMethod/Post.php中的操作失败< / p>
我在localhost上测试它。
任何建议。
感谢。
答案 0 :(得分:0)
@jww的回答构成了我:
对于步骤(1),请参阅How do you sign Certificate Signing Request with your Certification Authority?。对于(2),请参阅How to create a self-signed certificate with openssl?。后者还向您展示了如何创建签名请求(而不是自签名证书)。它们是相同的步骤 - 唯一不同的是签名请求缺少-x509选项。
答案 1 :(得分:0)
更改
$verify=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
要
$ch = curl_init("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$verify = curl_exec($ch);