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 wincc已组态的变量过多
  • ¥60 如图:直线与椭圆X轴平行,求直线与椭圆任意一点的相切坐标计算公式
  • ¥50 如何用python使用opencv里的cv::cudacodec::VideoWriter函数对视频进行GPU硬编码
  • ¥100 c#solidworks 二次开发 工程图自动标边线法兰 等折弯尺寸怎么标
  • ¥15 halcon DrawRegion 提示错误
  • ¥15 FastAPI Uvicorn启动显示404
  • ¥15 centos7.9脚本,怎么排除特定的访问记录
  • ¥15 关于#Django#的问题:我的静态文件呢?
  • ¥15 关于CPLEX的问题,请专家解答
  • ¥15 cocos的点击事件 怎么穿透到 原生fragment上。