2017-08-22 7 views
0

私は自分のウェブサイトにre-CAPTCHAを使用していますが、LOGINをクリックするとロボット認証が失敗しました。再試行してください。毎回:/再キャプチャができません

ありがとうございます。

あなたがより良いスクリプトをお持ちでしたら、私に教えてください。ここで

 if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) 
    { 
     $secret = '**************'; 

     $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']); 
     $responseData = json_decode($verifyResponse); 

     if($responseData->success) 
     { 

     }else{ 
       echo "<div class='container'><div class='alert alert-danger'><p>Robot verification failed, please try again.</p></div>"; 
      } 
    }else{ 
      echo "<div class='container'><div class='alert alert-danger'><p>Please click on the reCAPTCHA box.</p></div>"; 
    } 
+0

以下の回答があります。それが解決したら、それを解決済みとしてマークしてください。 –

+0

「うまくいかない」というのは、数分前に同じことを投稿(および削除)した質問と全く同じ意味です。トローリングを終了しますか?無料のデバッグサービスとしてStackを使用します。 –

答えて

0

は、私がサーバー上でGoogleのreCAPTCHAのを処理する方法である:キャプチャチェックを処理するため

//process captia response with a custom method. 
$captcha = checkCaptia($_POST['g-recaptcha-response']); 

if ($captcha){ 
    mailLead(); 
} 
else{ 
    header('location: https://...'); 
    die(); 
} 

方法...

function checkCaptia($captcha){ 
    $url = 'https://www.google.com/recaptcha/api/siteverify'; 

    $data = array(
     'secret'=>';jaskdf;asdkjf', 
     'response'=>$captcha, 
     'remoteip'=>$_SERVER['REMOTE_ADDR'] 
    ); 

    $options = array(
     'http' => array(
     'header' => "Content-type: application/x-www-form-urlencoded\r\n", 
     'method' => 'POST', 
     'content' => http_build_query($data) 
     ) 
    ); 
    $context = stream_context_create($options); 
    $result = json_decode(file_get_contents($url, false, $context),TRUE); 

    return $result; 
} 
0

扱うとき、私は作曲のためにreCAPTCHAのパッケージを使用キャプチャ。

あなたが何であるかを作曲わからない場合、私はあなたがhttp://composer.org/

ComposerはPHPの依存関係のマネージャーであるに頭を提案し、近代的なPHPアプリケーションを構築するとき、それは本当に便利です。

reCAPTCHAのパッケージ:https://packagist.org/packages/google/recaptcha

コードサンプルもリンクに含まれています。

関連する問題