开发者

Automatically unban users after a period of time

I would like to set up temporary ban system on my site to ban users for example only for one day or one week. I can choose开发者_运维问答 the duration of the ban and appropriate record is made into the database so I would like to know if the is a way to automatically update that record when the ban period is over... or what else would you suggest?


I would create a separate table for ban records. Each record would contain:

  • The user who was banned (foreign key).
  • Who made the ban (foreign key).
  • The time the ban was made.
  • The time the ban expires.
  • The reason for the ban.
  • The IP address of the user at the time the ban was made.
  • If the ban is still active (in case you decide to unban a user before the full time expired).

Perhaps some other information too, depending on what you want to track. When a ban expires it is a good idea not to delete the record from the ban table. This means that you have a log of which bans you have made which can be useful in working out who the repeat offenders are.

Another issue you might have is people who deliberately try to cause problems by complaining about unfair bans and lying about when and why they were banned and unbanned. If you keep a complete log of all bans it is much easier to deal with these people.


I would save the end date (and maybe time) of the ban in the database. As soon as the user tries to log in, you can compare the current date(time) to the end date; if it's newer, the user isn't banned and can log in. If your users have profiles, you can do the same: compare the current date(time) to the ban's end and show "Banned" based on that information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜