2016-07-24 5 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: "Notice:Undefined variable"と "Notice:Undefined index"]の重複している可能性があります(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>'; 
    } 
} 

?> 
関連する問題