如何确保人员通过reCAPTCHA验证


How to make sure that the person passed reCAPTCHA validation

我有一个联系人PHP联系人文件,我在"联系人"窗体下的HTML主题中添加了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 = "myemail@myemail.com";
$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语句,检查输入的captcha是否与定义的相同。也许是粘贴表格标记?看看你用的是哪种captcha?

尝试从这里使用这个片段:

<?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
  }
?>