Google No captcha Recaptcha无效

时间:2015-04-13 00:55:00

标签: php html css captcha recaptcha

希望有人可以帮助..我有小部件显示没有验证码recaptcha我已经在互联网上找到了我想尝试使用的代码因为我不是那么好用PHP但它似乎只工作部分。每次我点击框或我不,我尝试发送电子邮件说,请检查验证码。

这是我在我的邮件confirm.php文件中的内容,这是服务器端(我不认为需要发布小部件代码,因为它显示和工作,这是第1步)

$email;$message;$sujet;$header;$captcha;
    if(isset($_POST['email'])){
      $email=$_POST['email'];
    }if(isset($_POST['message'])){
      $email=$_POST['message'];

}if(isset($_POST['sujet'])){
      $email=$_POST['sujet'];
}if(isset($_POST['header'])){
      $email=$_POST['header'];


    }if(isset($_POST['g-recaptcha-response'])){
      $captcha=$_POST['g-recaptcha-response'];
    }
    if(!$captcha){
      echo '<h2>Please check the the captcha form.</h2>';
      exit;
    }
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LcIAgETAAAAAEjbARzUsrkgBIHAeE8QmsNE3US-&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
    if($response.success==false)
    {
      echo '<h2>You are spammer ! Get the @$%K out</h2>';
    }
    else
    {
      echo '<h2>Thanks for posting comment.</h2>';
    }

1 个答案:

答案 0 :(得分:2)

根据您的需要修改此代码。

<?
    $APIkey = "API KEY";
    $postresult=$_POST['g-recaptcha-response'];
    $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$APIkey&response=$postresult");

    if (strpos($response, 'true')){
        //Captcha is valid, do whatever.
    } else {
        //Captcha is invalid. Tell them to go away.
    }

?>