I am writing an ip ban for my small , silly , self-made forum .
I have a question : Is it possible to create a new row in a mysql table , that would auto-delete itself in a definite time ?
I want to create a ip bans for definite times...
what other techniques can be used for this purpose ?
I know that phpbb 3 forums have this thing
IP bans
Moderator: General Moderators
Re: IP bans
No for a bunch of reasons. A table is just a bucket of data sitting there waiting for some process to come along and use it. Also, it's usually a really bad idea to design a system so that you're constantly deleting records.Monopoly wrote:I am writing an ip ban for my small , silly , self-made forum .
I have a question : Is it possible to create a new row in a mysql table , that would auto-delete itself in a definite time ?
I want to create a ip bans for definite times...
what other techniques can be used for this purpose ?
I know that phpbb 3 forums have this thing
The way to manage such things is to put a date field in the user profile table for the date the ban is to be lifted. Then every time you check to see if a user is banned, you don't check to see if there is a "banned" record there, you just compare the date, if any, in that field, and if the current date is later than that date, he is no longer banned. You do this in the user profile record and don't set up another table for this.
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Re: IP bans
To add on to what califdon said, phpbb forums implements this "expire" functionality by checking, on retrieval, whether or not the unban timestamp is earlier than the current time. If you were really worried about keeping the database in shape, you could easily have cron run a "prune" command, which would basically be a (warning, pseudo-sql; be sure to check up on date comparisons if you're not using Unix timestamps) DELETE FROM table WHERE time < TIME(). Hope that helps.