Jump to content

Recommended Posts

Hey

 

I would like to know the best way to allow a user to do something once every 24 hours.

 

My thought was to make a table and store the date in that, but it's a reputation program and what if that user gave rep to 100 people that day, that's 100 tables filled just to hold info so he can't give any of those people rep again.

 

I'd prefer you didn't actually code it out, just pointed me in the right direction.

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/159208-once-every-24-hours-in-php/
Share on other sites

- Have a field in your database for storing the last time they performed this action.

- Every time they perform this action you need to do a check to see if the difference between the last time they committed this action and the current time, was > 24 hours.

- If it is > 24 hours, let them perform the task and update the field with the current time.

- If not, display your error message, and leave the time that was in the field.

Record the last time the user gave someone a rep in the database. Then use SQL to check if the user has given 100 rep points that day AND the time of the last rep given is less than 24 hours ago.

 

Like what the other 2 people says, but also check for how many reps the user given that day if you want to allow 100 per day.

I think the OP is wanting the user to be able to hand out rep all day long to people, but he can't click the same person again until 24hrs have passed. 

 

All you need is a single table.  3 columns: userId, friendId, timestamp.  Every time a user clicks on a link, your script checks to see if a row exists matching the user and friend.  And the timestamp is less than 24 hours.  You would then have a cronjob setup to run a script every 24 hours to prune old entries. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.