Please tell me how to use PHP to limit the number of user logins.
我只是一条咸鱼哈
我只是一条咸鱼哈 2017-08-29 22:16:14
0
2
3773

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

我只是一条咸鱼哈
我只是一条咸鱼哈

即使是小小的人物,也有他自己精彩的故事

reply all(2)
逸先生
$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() 秒
}


逸先生

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 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╮(╯▽╰)╭
    我只是一条咸鱼哈 author 2017-08-30 11:33:06
  • reply O(∩_∩)OThank you
    我只是一条咸鱼哈 author 2017-08-30 13:56:00
  • reply 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
    逸先生 author 2017-08-30 12:11:48
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!