User posting wait time question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ziycon
    Contributor
    • Sep 2008
    • 384

    #1

    User posting wait time question

    I have a comment form and I want to stop users flooding the site with comments and potentially crashing the site.

    I have a table that all comments are submitted to.

    I was thinking to create a table that will create an entry when a user submits a new comment which will contain the users id and a datetime stamp of when the comment was added.

    There I would have a check when a comment is added to see if the user has an entry in the database and check the difference between the entry datetime and the current submission datetime.

    There would be a trigger in the database to remove entries once they hit a certain criteria like a certain amount of time has elapsed since being added.

    My problem here would be how to get the time difference between two datetime stamps in PHP, they would be formatted like so '2010-06-17 13:22:11'.

    Any ideas/help much appreciated.
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    see strtotime() in php manual.

    You should always store date and times in unix epoch time. (an integer) then choose to display it however. If you store it in one format, you would have to convert it to a timestamp (from a string like you have above) than back to the format you wanted.

    To keep things simple, you can also use a session variable that stores that last comment time. This will reduce the load on your database, but does not prevent it completely. Think of it as a front-line defense.

    Apply the DB time stamp solution as well because anyone can clear their session and submit another comment.

    Dan

    Comment

    Working...