gpt4 book ai didi

php - 新的 Google reCAPTCHA 始终无法通过本地主机进行验证

转载 作者:可可西里 更新时间:2023-11-01 00:13:38 26 4
gpt4 key购买 nike

新的 Google reCAPTCHA使用 CodeIgniter 2.2.2每次我尝试运行我的测试时,它都会在加载很长时间后返回一个错误的结果,并显示以下警告消息:

A PHP Error was encountered

Severity: Warning

Message: file_get_contents(https://www.google.com/recaptcha/api/siteverify?secret=PUBLICKEY&response=03AHJ_VuvOwCxIKqGoZXeEOWvDxMjYrBsH9HyWpbxg1YmBTThs8gINjC5yEQOG0fVikDPY3GXemQVrB6DT965o0LARL2rRDP-U6m9Y9DSFdDvz55vwsewe4--m0NfssykJZ3et6zItKH7mNsDIi1LLtPrn7vaQmCGlK3LW2hS4Q8TMDhjTW-tecmCRbonCcTcvMN4gHnWuGzSzUFUlOPxAlSHEvkBHspZb5SnGLNakZ5rrF591LL9SS8NrZErFVO3EySpW_CCG26uDhpMJW5y5B_3nZnBYZqpmf0eIIMy5w3rk2FjJrPw2G8Kj98Cv1B1xJcXBgML7uCnZRmc7WDZhzFoI2JAeuEBNwQkQJvSGXsGLGkewz1ClPiQwzYZRlwEpgo2Zpkri6lrIlNMIc0dtmhM7U172LGELgjbNKFAW29Aq8wTOCwC2tztWlTn_8mq9SrS_mhhs7iaG&remoteip=127.0.0.1): failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

Filename: controllers/cap.php

这是我的html代码

  <!DOCTYPE html>
<html lang="en">
<head>
<title>TEST</title>
</head>

<body>

<form action="validation" method="post">

<label for="name">Name:</label>
<input name="name" required><br />

<label for="email">Email:</label>
<input name="email" type="email" required><br />

<div class="g-recaptcha" data-sitekey="My_Public_Key"></div>

<input type="submit" value="Submit" />

</form>

<!--js-->
<script src='https://www.google.com/recaptcha/api.js'></script>

</body>
</html>

这是我的 php 文件:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class cap extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->database();
$this->load->model('users_model', 'user');
$this->lang->load("message",$this->session->userdata('language'));
}
public function index() {

$this->load->view("cap");
}
public function validation()
{
$email;$comment;$captcha;
if(isset($_POST['email'])){
$email=$_POST['email'];
}if(isset($_POST['comment'])){
$email=$_POST['comment'];
}if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
remoteip=".$_SERVER['REMOTE_ADDR']);
$response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=MyPrivateKey&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);

if($response['success'] == false)
{
echo '<h2>Wrong</h2>';
}else
{
echo '<h2>Correct</h2>';
}
}
}
?>

(当然我是通过google api网页生成我的公钥和私钥的)

有什么想法吗?我需要在我的 php 中打开 curl 或其他东西吗?

最佳答案

您的 php.ini 中的 allow_url_fopen = Off 可能会阻止 file_get_contents 打开 URL。

您可以为此使用 cURL,如下所示:

    $fields = array(
'secret' => "MySecretKey",
'response' => $captcha,
'remoteip' => $_SERVER['REMOTE_ADDR']
);
$ch = curl_init("https://www.google.com/recaptcha/api/siteverify");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
$response = json_decode(curl_exec($ch));
curl_close($ch);

关于php - 新的 Google reCAPTCHA 始终无法通过本地主机进行验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30181330/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com