zackcez Posted May 12, 2008 Share Posted May 12, 2008 I'm working on a site and I was just wondering if anyone could just post a simple script that will only execute something if you havn't done it in the past 24hours and if you have, give a simple customizable error message. I was thinking it would have to be in a cookie but I'm not sure how to do that kind of stuff... Thanks, Zack Link to comment https://forums.phpfreaks.com/topic/105204-solved-once-per-24-hours/ Share on other sites More sharing options...
cunoodle2 Posted May 12, 2008 Share Posted May 12, 2008 Look into cron jobs for this. Probably have to be a variable with a time stamp in a database Link to comment https://forums.phpfreaks.com/topic/105204-solved-once-per-24-hours/#findComment-538678 Share on other sites More sharing options...
LooieENG Posted May 12, 2008 Share Posted May 12, 2008 <?php if ( isset($_COOKIE['24']) ) { // 24 hours hasn't passed yet echo 'Error message.' } else { // It's been 24 hours, do what's supposed to happen and set another cookie setcookie("24", "24 Hours", time()+3600*24); } ?> Not sure if that would work, don't really understand cookies myself =P Link to comment https://forums.phpfreaks.com/topic/105204-solved-once-per-24-hours/#findComment-538680 Share on other sites More sharing options...
DarkWater Posted May 12, 2008 Share Posted May 12, 2008 Store the time of the action in the database, then do something like: //Do query stuff $row = mysql_fetch_array($result); $time = $row['lasttime']; if ($time+(60*60*24) < time()) { echo "Sorry, you need to wait 24 hours since you last did this action."; } else { //do stuff } Link to comment https://forums.phpfreaks.com/topic/105204-solved-once-per-24-hours/#findComment-538683 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.