Php 在本地测试reCAPTCHA。在mac上验证,但在windows上不验证
我正在两个操作系统上本地测试reCAPTCHA。生成的密钥用于域localhost和127.0.0.1 在我的mac电脑上,同样精确的文件可以完美地工作。我将上述文件复制到我的windows计算机上,我的响应总是返回NULL HTMLPhp 在本地测试reCAPTCHA。在mac上验证,但在windows上不验证,php,recaptcha,Php,Recaptcha,我正在两个操作系统上本地测试reCAPTCHA。生成的密钥用于域localhost和127.0.0.1 在我的mac电脑上,同样精确的文件可以完美地工作。我将上述文件复制到我的windows计算机上,我的响应总是返回NULL HTML 这是一个测试 PHP(服务器) 感谢您提供的任何帮助 预期的结果是什么?而windows/osx可能不应该在此处标记。已删除windows/osx标记。我只是想知道为什么我在不同的操作系统上会有不同的结果,以及我的代码是否有问题。这可能只是配置问题。谢
这是一个测试
PHP(服务器)
感谢您提供的任何帮助 预期的结果是什么?而windows/osx可能不应该在此处标记。已删除windows/osx标记。我只是想知道为什么我在不同的操作系统上会有不同的结果,以及我的代码是否有问题。这可能只是配置问题。谢谢!我上传到了一个测试服务器,它工作得很好。
<!DOCTYPE html>
<html>
<head>
<title>This is a test</title>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<form action="/form.php" method="post">
<input type="text" name="name" placeholder="name"><br>
<input type="text" name="phone" placeholder="phone"><br>
<div class="g-recaptcha" data-sitekey="PUBLIC_KEY"></div>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php
if (isset($_POST['g-recaptcha-response'])) {
$captcha = $_POST['g-recaptcha-response'];
$privatekey = "SECRET_KEY";
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => $privatekey,
'response' => $captcha,
'remoteip' => $_SERVER['REMOTE_ADDR']
);
$curlConfig = array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $data
);
$ch = curl_init();
curl_setopt_array($ch, $curlConfig);
$response = curl_exec($ch);
curl_close($ch);
}
$jsonResponse = json_decode($response);
if ($jsonResponse->success === true) {
echo '<br><p>CAPTCHA was completed successfully!</p><br>';
}
else {
echo '<p>Please go back and make sure you check the security CAPTCHA box.</p><br>';
}
?>