Home  >  Q&A  >  body text

Please tell me how to use PHP to limit the number of user logins.

Simple is fine. I hope you can tell me what method to use to do it and give you some ideas. Thank you.

我只是一条咸鱼哈我只是一条咸鱼哈2580 days ago3714

reply all(2)I'll reply

  • 逸先生

    逸先生2017-08-30 12:47:16

    $user = "xx";
    $pass = "xx";
    $waittime = 241231; //根据$user在数据库中查询出来的时间
    $times = 0; //根据$user在数据库中查询出来的尝试次数
    
    if ((time() - $waittime) > 0) {
    	if (/*根据user和pass去数据库查询*/) {
    		//账号和密码存在
    		//登陆成功
    		//数据库中 waittime = 0;times= 0;
    	} else {
    		//账号和密码不存在
    		//登陆失败
    		//数据库中 times= $times+1;
    		if (($times + 1) == 3) {
    			//数据库中 times= 0;waittime = time() + 30 * 60(当前时间+半小时);
    		}
    	}
    } else {
    	//提示 还需等待$waittime - time() 秒
    }


    reply
    0
  • 逸先生

    逸先生2017-08-30 10:44:24

    When you talk about limiting the number of logins, do you mean to limit the number of logins per day, or do you mean that once a person logs in, he cannot log in again when he is online? If it is restricted, one person can log in 5 times a day. It can be designed like this. Add a field to the user table, login_times tinyint (1). Every time you log in, it will be judged whether the value is greater than or equal to 5. If it is less than 5, the login is successful and the number of times is increased by one. The server uses scheduled tasks. This value will be set every early morning. Data cleared 0

    reply
    1
  • 我只是一条咸鱼哈

    Sorry, what I said was not very clear. What I want to ask is: Suppose a user logs in three times and enters the wrong password each time. Then the user is restricted from trying to log in for 30 minutes. May I ask what method you should use to do it? I don’t have any ideas╮(╯▽╰)╭

    我只是一条咸鱼哈 · 2017-08-30 11:33:06
    我只是一条咸鱼哈

    O(∩_∩)OThank you

    我只是一条咸鱼哈 · 2017-08-30 13:56:00
    逸先生

    Still restricted by fields, the user table adds two fields times tinyint(1) waittime int(11) default 0; every time you log in, 1 first determines whether the waittime value is 0 based on the user's login name, which is 0 , you can log in, continue to determine the password, if it is not 0, prompt him to wait ((waittime - time()) / 60) minutes, 2. If the value of waittime is 0, determine whether the login name and password are correct, correct, log in Successful, incorrect, times plus 1, if times = 3, then, waittime = time()+ 30 * 60, after successful login, times=0, waittime=0

    逸先生 · 2017-08-30 12:11:48
  • Cancelreply