[thelist] Adding 15 mins to PHP time...

Ken Robinson kenrbnsn at rbnsn.com
Wed Dec 13 09:41:57 CST 2006

Quoting Tris <beertastic at gmail.com>:

> I'm creating a timer for todays lucky client...
> They wanna hit start and have a timer on screen across all pages..
> No prob doing that in javascript, so I'm gonna create a session called
> timer with the date value:
> date("H:i:s"); Giving: 15:42:34 etc.. (the precise users start time)
> What I need to do is on each page, check the current server time, and
> if it's 15 mis higher than my session, redirect the user to a thank
> you page and destroythetimer session..
> soooo...
> How can I add 15 mins to a date function?
> (I'm also gonna have to fee different times to the javasript ticker,
> but that'll be easiy once I kno whow to knock off time from um, well,
> time :-p  )

To add times in PHP, you need to convert everything to the number of seconds
since 1-1-1970 (zero date in PHP)

To make it simple, just store the integer value in your session variable:

$_SESSION['users_start_time'] = time();

15 minutes is 900 seconds, so to see whether the current time is more than 15
minutes later, do something like this:

$time_dif = time() - $_SESSION['users_start_time'];
if ($time_dif > 900) {
      header('location: thankyou.php');


More information about the thelist mailing list