1

I already know that mktime returns the number of seconds since the epoch (Jan 1 1970 00:00:00 GMT) so the timestamps are GMT based.

I have a PHP web app for school fairs and it's written using Kohana 3.2. When a fair is scheduled I create a timestamp using mktime that is stored in the fairs "date" field. Before the fair starts if you try to view fair it will automatically send you to the promo page for the fair. If you try to view the promo page and the fair has started you will be sent to the view page. So you can see I am doing two checks.

The promo page uses PHP to store the fairs timestamp in a hidden field. A javascript countdown routine is called using that timestamp and begins counting down the remaining time left between the fair's date and the current time (converted to EST). The the timer reaches 0 meaning the fair has started, the page is redirected to the view page.

The view page has some code setup to check if the fair has started and it looks like this:

if( mktime() < $fair->date ) Request::current()->redirect('/fair/promo/' . $id);

However when the above statement is processed it redirects back to the promo page where the timer immediately goes to zero and tries to send me back to the view page. Big infinite loop.

Here is how I get the time with javascript on the promo page.

var st = srvTime();
var d = new Date(st);
var now = Math.round( d.getTime() / 1000);
now=now+3600; //adjust to EST

So the question falls back to mktime(). According to php.net, "Arguments may be left out in order from right to left; any arguments thus omitted will be set to the current value according to the local date and time." So does that mean if I call mktime() on a server in CST, the number of seconds passed since the epoch = CST time - Epoch ???

pogeybait
  • 3,065
  • 2
  • 21
  • 23
  • Where is the code that is looping infinitely? – FoolishSeth Oct 25 '12 at 02:06
  • 2
    if you output epoch time you can just use JavaScript with `new Date(epochValue)` which will be displayed in the local time of the browser and you can work with it from there. Sticking to using epoch time for data transfers is a way to avoid the potential for enormous headaches due to time zone issues. – Matt Whipple Oct 25 '12 at 02:27
  • The infinite loop is happening when the javascript timer on the promo page counts down to zero (meaning the fair has started) and redirects to the view page. Then the php code I pasted above doesn't think the fair has started so it send the user back to the promo page. Go back to the beginning of this paragraph. – pogeybait Oct 25 '12 at 02:30
  • I edited my question to be a little more clear. – pogeybait Oct 25 '12 at 02:47

1 Answers1

1

Arguments may be left out in order from right to left; any arguments thus omitted will be set to the current value according to the local date and time.

Joe Brown
  • 637
  • 3
  • 5
  • Ok my bad. You were quoting from the php mktime() page. – pogeybait Oct 25 '12 at 04:01
  • So mktime() with no args will return the number of seconds since the epoch using local date and time. So the timestamp will be for CST if the server in in the CST timezone? – pogeybait Oct 25 '12 at 04:21
  • I found the answer. I went into the bootstrap.php for Kohana and set the default time zone to EDT which is what I needed. Even if you dont know Kohana the PHP command I used was date_default_timezone_set(). Fixed! Yay! – pogeybait Oct 25 '12 at 05:50