2016-07-24 221 views
0
if (isset($_POST['btnSubmit'])) 
    { 
     if(isset($_POST['g-recaptcha-response'])){ 
      $captcha=$_POST['g-recaptcha-response']; 

     } 
     echo $captcha; 
     if(!$captcha){ 

      echo '<h2>Please check the the captcha form.</h2>'; 
      exit; 
     } 
     $secretKey = "================"; 
     $ip = $_SERVER['REMOTE_ADDR']; 
     $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip); 
     $responseKeys = json_decode($response,true); 
     if(intval($responseKeys["success"]) !== 1) { 
      echo '<h2>You are spammer ! Get the @$%K out</h2>'; 
     } else { 
      echo '<h2>Thanks for posting comment.</h2>'; 
} 

这是我的代码,当点击提交表单,然后不确定的变量$ chaptcha请帮我

+1

你有没有证实,'$ _ POST [ 'G-的reCAPTCHA响应']'的定义? – IzzEps

+1

发表您的表单代码太 – Panda

+0

[PHP的:“注意:未定义的变量”和“注意:未定义的索引”]的可能重复(http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-注意,未定义指数) – Jocelyn

回答

0

PHP抛出通知,如果你引用了尚未创建一个变量,虽然代码仍然“作品”,Read this answer

尝试这样:

<?php 

if (isset($_POST['btnSubmit'])) { 
    if(isset($_POST['g-recaptcha-response'])){ 
     $captcha=$_POST['g-recaptcha-response']; 
     echo $captcha; 
    }else { 
     echo '<h2>Please check the the captcha form.</h2>'; 
     exit; 
    } 

    $secretKey = "================"; 
    $ip = $_SERVER['REMOTE_ADDR']; 
    $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip); 
    $responseKeys = json_decode($response,true); 

    if(intval($responseKeys["success"]) !== 1) { 
     echo '<h2>You are spammer ! Get the @$%K out</h2>'; 
    } else { 
     echo '<h2>Thanks for posting comment.</h2>'; 
    } 
} 

?> 
相关问题