if($loginErrorV){
    if(isset($_COOKIE['login'])){
        if($_COOKIE['login']<3){
            header('Location:login.php');
            $attempts = $_COOKIE['login'] + 1;
        } else {
            header('Location:register.php');
        }
    }
}
你不是已經寫好了嗎

解决方案 »

  1.   

    原來你沒有set cookie,所以不行。
    if($loginErrorV){
        if(isset($_COOKIE['login'])){
            if($_COOKIE['login']<3){
                setcookie("login",$_COOKIE['login'] + 1, time()+3600*24);
                header('Location:login.php');
                $attempts = $_COOKIE['login'] + 1;
            } else {
                header('Location:register.php');
            }
        }else{
                setcookie("login",0, time()+3600*24);
        }
    }
      

  2.   

    cookie也可以实现,if (isset($_COOKIE['user']) && isset($_COOKIE['login_times'])) {
                    setcookie("login_times", $_COOKIE['login_times']+1, time()+3600);
                    echo $_COOKIE['user'] . "<br/>";
                    echo $_COOKIE['login_times'];
                    if ($_COOKIE['login_times'] > 3) {
                        setcookie("user", "", time()-3600);
                        setcookie("login_times", "", time()-3600);
                        header("Location:user.php?act=register_page");
                    }
                } else {
                    setcookie("user", $user_arr[0]['user_name'], time()+3600);
                    setcookie("login_times", 1, time()+3600);
                }如果需要行为分析:可以用一个新表来记录用户的登录和注册行为 对于系统的分析和统计会更好
    CREATE TABLE `user_log` (
      `id` int(6) NOT NULL AUTO_INCREMENT,
      `user_id` int(6) NOT NULL,
      `user_action` int(1) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8
    加上时间字段,登录失败,在一定时间范围内锁定账号,统计查询失败次数,登录失败新增对应记录