2017-02-12 44 views
-2

这是我的代码我目前的工作。但我只需要点击重定向到下一个页面重定向后succesfull谷歌recapta

<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

好的,这很好,所以从我们你要什么? – nogad

+0

@Irfan Ali为什么不张贴您的代码,因为我们在这里通过解决问题来帮助您解决问题,而不是为您编写整个代码......请花几分钟时间发布您的代码并将其添加到您的代码中点击“编辑”链接提问?换上别的,因为这应该保密的,应该由你只知道一些秘密/私有密钥。 – jagb

+0

@jabg我没有它查收 –

回答

0

相反echo'ing“登录成功”,使用:

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

与$ URL设置为你想要重定向到任何网页。

+0

我需要完整的代码..上面的脚本是表单提交..我想重定向用户,如果他们是真正的..只是上点击 –

1

要发布仅适用于实际的点击是不反对机器人的答案,你需要创建一个表单与一个隐藏的标记,并检查验证码和令牌是有效的,然后在验证用户登录。

<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'); 
    } 
}