Jump to content

[SOLVED] Once Per 24 Hours...


zackcez

Recommended Posts

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

<?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

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

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.