dsafq2131321 2018-09-08 18:50
浏览 68
已采纳

谷歌ReCaptcha v2坏php脚本

I'm trying to make Login Panel, all is working fine without ReCaptcha. But when I verify that I am not a robot and log in, it shows that there is an incorrect ReCaptcha.

<?php
 require_once('includes/config.php');
if( $user->is_logged_in() ){ header('Location: index.php'); exit(); }
if(isset($_POST['submit'])){
    if (!isset($_POST['username'])) $error[] = "No username.";
    if (!isset($_POST['password'])) $error[] = "Type pass.";
    if(!$captcha){
        echo 'Check ReCaptcha';
        exit;
}
    $secretKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    $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 'Check ReCaptcha';
    exit;
} else {
$username = $_POST['username'];
if ( $user->isValidUsername($username)){
        if (!isset($_POST['password'])){
            $error[] = 'Type pass';
        }
        $password = $_POST['password'];

        if($user->login($username,$password)){

            $_SESSION['username'] = $username;
            header('Location: memberpage.php');
            exit;

        } else {
            $error[] = 'Wrong pass.';
        }
    }else{
        $error[] = 'Wrong pass.';
    }
}

}
  • 写回答

1条回答 默认 最新

  • dongqu3623 2018-09-08 19:38
    关注

    you can check for captcha is empty or not and check is verify or not:

    $secretKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    $captcha  = $_POST['g-recaptcha-response'];
    
    if($captcha == null) {
        echo 'Check ReCaptcha';
        exit;
    }
    $response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $secretKey . "&response=" . $captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']), true);
    
    if ($response['success'] != true) {
        echo 'captcha is wrong!';
        exit;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退