Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top