如何确保通过reCAPTCHA验证的人
问题描述:
我有一个联系人的PHP联系人文件, 我在我的HTML主题下添加了reCAPTCHA,在联系表格 下,但我希望代码确保客户或想要的人联系通过reCAPTCHA ..!如何确保通过reCAPTCHA验证的人
这里是我的PHP代码联系:
<?
$name = $_POST[name];
$email = $_POST[email];
$type = $_POST[type];
$message = $_POST[message];
if ($name == "") {
die('name null');
}
if ($type == "" || $email == "" || $message == "") {
die("not null");
}
$myemail = "[email protected]";
$s = "$name";
$body = "<b>Message from Client</b> <br><br> Name: <b>$name</b><br> Package: <b>$type</b><br> E-mail: <b>$email</b><br> Message: <b>$message</b>";
$headers = 'From: '.$email."\r\n".'Content-Type: text/html; charset=utf-8'."\r\n";
mail($myemail, $s, $body, $headers);
header('Content-Type: application/json');
echo json_encode(array('response' => 'success'));
?>
答
使用if语句,检查是否输入了验证码是一样的定义。也许粘贴形式标记?查看您正在使用哪个验证码?
答
尝试使用这个片段来自here:
<?php
require_once('recaptchalib.php');
$privatekey = "your_private_key";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
// Your code here to handle a successful verification
}
?>
+0
,但我没有使用recaptchalib.php文件我只有HTML的联系表格+ PHP文件发送表单 –
可以让这个对我即时通讯不亲PHP程序员..! –
在此贴上表格的标记。所以我可以看看。 –
我使用谷歌recaptcha https://www.google.com/recaptcha/intro/index.html –