简体   繁体   中英

PHP Comments every x hours

I am a beginner at PHP, but I am wanting it that a user is able to post a comment 10 times, in the period of 24 hours. If they reach 10 comments before this 24 hours is up, they will get a message saying something like "You can not post any more comments", and after the 24 hours, they are able to post again.

Any ideas on how I can do this?

Thanks.

Store the username and timestamp with each comment in your database.

When someone tries to comment, make an SQL query to return the comments where that user made the comment and the time was in the last 24 hours.

If there are 10 results, show the user an error message.

Otherwise process as normal.

If you have registered users you can store comments and date in database in count them each time you add new comment. If you haven't registered users you can store it in cookies. Read about cookies .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM