Log in

View Full Version : date and time redirection



gisfrancisco
04-16-2007, 03:04 AM
I have a game script i'm modifying and i'm stuck.I need to redirect based on my servers date and time.I need to restrict player to a certain time frame to play.I can't figure out how to span two days.I need to redirect to the games at Fri 1800 and end Sat 1800.

I found this on this forum and it's close but doesn't span two dates.

<?php
$curTime = date('Gi',time()); //gets current hour [24 hour]
$hour = date('G');
$minute = date('i');
$day = date('w');
$m = $hour * 60 + $minute; // Minutes since midnight.
if(
$day == 6 // Saturday...
&& $m >= 735 // ... after 12:15...
&& $m <= 1035 // ... but before 17:15...
) header("Location: saturdayafternoon.php");
else if(
$day == 4 // Wednesday...
&& $m >= 1155 // ... after 19:15...
&& $m <= 1335 // ... but before 22:15...
) header("Location: http://full path wednesdaynight.php");
?>

Any help would be appreciated.Thanks in advance.

JShor
04-16-2007, 05:31 AM
Hi, What will be easier is if you used a Jscript timer, and have the php code redirect the user when the time is set.

djr33
04-16-2007, 06:32 AM
Hmm? Why?

This is quite possible with PHP.


<?php
if ((date('G')>=18 && date('w')==5) || (date('G')<=18 && date('w')==6)) {
$loc = "http://...gamepage.php";
}
else {$loc = "http://...other.php"; }
header("Location: $loc");
?>

gisfrancisco
04-16-2007, 12:58 PM
Thanks,i wanted to use php,because my understanding of jscript is it would use the clients computer time and not the servers.Thanks again.

djr33
04-16-2007, 01:30 PM
Exactly. JScript is a very different (and almost surely wrong) answer in this case.

You're welcome.