You create a table called loginlog (log of all logins)
table loginlog
id integer autoincrement primary key
user_id integer
logindate date
logincount integer
unique key userdate(user_id, logindate)
Then you create a trigger before updating in the table
DELIMITER $$
CREATE TRIGGER bu_loginlog_each BEFORE UPDATE ON loginlog FOR EACH ROW
BEGIN
IF new.logincount > 150 THEN SELECT * FROM create_error_only_150_logins_allowed
END $$
DELIMITER ;
In your php code follow these steps:
INSERT INTO loginlog (user_id, logindate, logincount)
VALUES ('$user_id',curdate(),1)
ON DUPLICATE KEY UPDATE logincount = logincount + 1
Check if insert failed. If the insert / update failed, your user has logged in> 150 times, and you can refuse the user.
This will only contain one entry per user per day. You can even delete past days from the loginlog table after x days.
Johan source
share