IP bans

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Monopoly
Forum Commoner
Posts: 41
Joined: Wed May 21, 2008 1:19 pm

IP bans

Post by Monopoly »

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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: IP bans

Post by califdon »

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
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.

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.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Re: IP bans

Post by Ambush Commander »

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.
Post Reply