Quote:
Originally Posted by vbplusme
I think you might need to use a javascript function to get were you want to go.
|
That would require a user to stay on the page for 10 minutes and not navigate away. Very not cool from a design standpoint.
Quote:
Originally Posted by Vaupell
A user clicks a botton / or another event happens that triggers a timestamp to be marked.
|
Very easy to add a timestamp to a database.
Quote:
Originally Posted by Vaupell
how would i go about counting 10 minuttes, and activate a trigger after
those 10 minuttes ?
|
Not very easy to make a "trigger" after 10 minutes. You might consider using what's known as a CRON job. CRON jobs are scripts that get executed every 5/10/15/30/60/1440 minutes. There's no real way to guarantee that the trigger will be executed exactly 10 minutes after someone sets the timestamp - the cron job will just run at the set intervals. So if someone initaties the trigger right before your cron job runs - then the script will pass them over since it hasn't been 10 minutes for them. They may have to wait 12 minutes, or even 15... All the way up to 19 minutes for the next cron job script to come along and unset the delay.
Quote:
Originally Posted by Vaupell
sort of a delay, and perhaps ewen if the user hits refresh
the display would just show something like 5minuttes togo.
|
Okay, hang on. Do you want a trigger or do you just want a delay? Because delays are much easier...
Say you've got a table in the database called "delay_timestamps"... It would have the fields "userid" and "timestamp".
Insert or update the field with the user like so
PHP Code:
$db->query_write("INSERT INTO ".TABLE_PREFIX."delay_timestamps (userid, timestamp) VALUES ".$userid.", ".time() );
// or...
$db->query_write("UPDATE ".TABLE_PREFIX."delay_timestamps SET timestamp=".time()." WHERE userid=".$userid );
// OR even better - this handles insert and update in 1 SQL statement
// but you have to set the userid field in the table as the key
// shouldn't be a problem since userids should be unique anyway
$db->query_write("INSERT ON DUPLICATE KEY UPDATE INTO ".TABLE_PREFIX."delay_timestamps (userid, timestamp) VALUES ".$userid.", ".time() );
Then in your "refresh" page you'll want to have a look see at the timestamp in the database and compare it with the current time:
PHP Code:
$wait_time = 5; // set the wait time they have before accessing the page again
$current_time = time();
$user_timestamp = $db->query_first("SELECT timestamp FROM ".TABLE_PREFIX."delay_timestamps WHERE userid=".$userid );
$number_of_seconds_since_stamp = $current_time - $user_timestamp;
$minutes_since_timestamp = $number_of_seconds_since_stamp / 60;
if($minutes_since_timestamp < $wait_time)
{
echo 'Sorry, you still have '. $wait_time-$minutes_since_timestamp .' minutes left...';
}
else
{
echo 'How sweet, you waited for me!';
}
This, of course, isn't the
exact code you'll want... Certainly you'll want to condense the code down, like the
$number_of_seconds_since_stamp variable is totally worthless - you can just divide by 60 on the fly. The timestamp variable in the database should probably be of type
INTEGER, be careful not to use something like SMALLINT because it's not big enough for the timestamp. However, this will require an action from your user - it's not a trigger. It will require the user to click refresh, or to view the page again in some way.
You might be able to work out some AJAX thing that starts up on every single page that checks for the time remaining and then starts an auto-refresh count down... But it'd be kinda wasteful in my opinion. Plus, some browsers disable the javascript redirects/refreshes.