2017-02-05 15 views
0

オープンインターネットに転送する前に、自分のパソコン(ローカルホスト)で開発中のサイトでGoogle Recaptchaの問題について少し助けが必要です。google recaptchaレスポンスがnullです[PHP、localhost]

Google Recaptchaにサインアップして、キーを取得しました。私は、PHPのページでこのフォームを作成しました:代わりにすべてがうまくている場合、私は、私はあまりにもキャプチャをチェックする別のPHPページにデータを提出し、ユーザー入力を検証するためにJSファイルを呼び出す送信ボタンの

<div> 
    <form action="" method="POST" name="formEmail"> 
    <section> 
     <ul class="formMail" id="ulMsg"> 
     <li> 
      <label for="msg">Messagge</label> 
     </li><li> 
      <textarea class="datoForm autoExpand" name="msg" id="msg" placeholder="Type Msg" rows='3' data-min-rows='3'></textarea> 
     </li> 
     </ul> 
    </section> 

    <div class="formMail" id="captchaContainer"> 
     <div class="g-recaptcha" data-sitekey="[Public_Key]"></div> 
    </div> 
    <br/><input type="button" value="Invia" onclick="formSubmit();">        
    </form> 
</div> 

。このPHPページのソースは:

if(isset($_POST['g-recaptcha-response'])){$captcha=$_POST['g-recaptcha-response'];} 
$secretKey = "[Private_Key]"; 
$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); 

ここに問題があります:私は何も得られません!試しました

var_dump($responseKeys); 

しかし、私はすべてがNULLです。私は他のエラーを出すことはありません、captchaは形式で罰金を表示し、定期的に動作するようです。私はlocalhostで作業していますので、私のIPアドレスは127.0.0.1です。これは役に立ちますが役に立たないでしょう。私はそれを貼り付ける "オープン"サイトを持っていない、私は間違って何をしていますか? Google recaptcha documentationによると

答えて

0

方法:POST

しかし、あなたは、この行にGETリクエストを送信している:

$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip); 

ソリューションは、すでにhereが提案されています。

+0

まず、お返事ありがとうございました。私はインターネット上で多くのチュートリアルでそのコードを見つけました。残念ながら、あなたが提案したソリューションを試しましたが、それはまだ動作しません... – Steve

0

ちょうど同じ問題がありました。この問題を引き起こしたのは<div>タグでした。

私のフォームは、フォームの一般的なレイアウトをフォーマットするために使用されるメイン<div>の範囲内でした。 <form>タグは、フォームレイアウトに使用していたメインの<div>内にある必要はありません。私は<form>タグを自分のフォームレイアウト<div>タグの直前に移動し、完全に動作するようになりました。

<table>タグでも同じことが起こります。フォームの書式設定に使用するテーブルの前に、<form>タグを開始する必要があります。

だからあなたの問題は、単に<form><div>です:

<div> <form action="" method="POST" name="formEmail">

わずか2個のタグを逆転させ、それが正常に動作します:HTMLタグ内

<form action="" method="POST" name="formEmail"> <div>

0

を:

個の
<head> 
<script src="https://www.google.com/recaptcha/api.js"></script> 
</head> 

<body> 

<form action="" method="POST"> 

<div class="g-recaptcha" data-sitekey="PublicKey"></div> 

<input type="submit" name="submit" value="Post comment"> 

</form> 

</body> 

インサイドPHPタグ:すべての

<?php 

if(isset($_POST['submit'])) { 
    if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) { 
     $secret = 'PrivateKey'; 
     $verifyResponse=file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']); 
     $responseData = json_decode($verifyResponse); 
     var_dump($responseData); //this line returns Null Value 

     if($responseData->success) { 
      // Logical Code 
     } 
     else { 
      echo 'Robot verification failed, please try again.'; 
     } 
    } 
} 

?> 
関連する問題