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

谷歌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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵