2017-02-12 6 views
-2

これは私のコードです、私は現在働いています。あなたがにリダイレクトしたいものは何でもページに設定$のURLでsuccesfullの後にリダイレクトGoogle recapta

echo '<script type="text/javascript">', 
    'location.replace("'.$url.'");' 
    ,'</script>'; 

:しかし、私は唯一の「成功しましログに記録されて」、使用をecho'ingの

<title></title> 
    <script src='https://www.google.com/recaptcha/api.js'></script> 
</head> 
<body> 
    <form method="post" action="index.php"> 
     <div class="g-recaptcha" data-sitekey="xxxxx"></div> 
     <input type="submit" /> 
    </form> 
</body> 



<?php 
    if($_SERVER["REQUEST_METHOD"] === "POST") 
    { 
     //form submitted 

     //check if other form details are correct 

     //verify captcha 
     $recaptcha_secret = "xxxxxxxxxg"; 
     $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']); 
     $response = json_decode($response, true); 
     if($response["success"] === true) 
     { 
      echo "Logged In Successfully"; 
     } 
     else 
     { 
      echo "You are a robot"; 
     } 
    } 
?> 
+2

ok、thats great、thats we want to what? – nogad

+0

@Irfan Aliコードを投稿すると、コード全体を記述するのではなく、問題を解決するために役立ちます。コードを投稿して、 "編集"リンクをクリックして質問しますか?これは秘密にしておき、あなただけが知っているはずなので、秘密/秘密鍵を別のものに置き換えてください。 – jagb

+0

@jabg私はそれを親切にチェックしました –

答えて

0

代わりに、次のページにリダイレクトする]をクリックする必要が。唯一の実際のクリックを投稿する

+0

私は完全なコードが必要です..上記のスクリプトはフォームの送信です..私はユーザーがリダイレクトしたい場合は、実際には..クリックして –

1

あなたは隠されたトークンでフォームを作成し、reCAPTCHAのとトークンが有効であるかどうかを確認し、その後にユーザログを検証する必要があり、ロボットに対する答えではありません。

<title></title> 
<script src='https://www.google.com/recaptcha/api.js'></script> 
</head> 
<body> 
<?php 

    if (!isset($_POST['Submit'])){ 
    // Genarate token 
    $token = md5(uniqid(rand(),TRUE)); 
    $_SESSION['token'] = $token; 
    $_SESSION['token_time'] = time(); 
    } 

?> 
<form method="post" action="index.php"> 
    <div class="g-recaptcha" data-sitekey="xxxxx"></div> 
    <input type="hidden" name="token" value="<?php echo $token;?>"/> 
    <input type="submit" /> 
</form> 

<?php 

if($_SERVER["REQUEST_METHOD"] === "POST") 
{ 
    //form submitted 

    //check if other form details are correct 

    //verify captcha 
    $recaptcha_secret = "xxxxxxxxxg"; 
    $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']); 
    $response = json_decode($response, true); 
    if($response["success"] === true) 
    { 
     // Logged In Successfully 
     if ($_POST['token'] != $_SESSION['token']){ 
      // Didn't came from the site 
      header('Location: login.php'); 
     } else { 
      header('Location: index.php'); 
     } 
    } 
    else 
    { 
     // Not Logged In Successfully 
     header('Location: login.php'); 
    } 
} 
関連する問題