Hi,
The school that I work at wants to prevent students from looking at certain pages on our Intranet during lesson time. I'm not that familiar with coding PHP but found this script out on the net.
<?php
$greenwich = (int) gmdate('Gi');
if (($greenwich >= 1200) and ($greenwich <= 1500)) {
header('Location: http://intranet/time/one.htm');
} else {
header('Location: http://intranet/time/two.htm');
}
?>
Where one.htm is the restricted page and two.htm is an error message.
It works fine for single times, but I'm unsure how to add more times to the script. Say, we want to allow the students to access pages between 7-9am, 10-11am, 12-1pm and 3pm onwards.
At the moment I'm using four files to redirect based on time, Time1.php, Time2,php etc.. If the time is incorrect on one it redirects onto the next but this is a long way of achieving this. I tried daisy chaining things together;
<?php
$greenwich = (int) gmdate('Gi');
if (($greenwich >= 0100) and ($greenwich <= 0855)) {
header('Location: http://intranet/time/one.htm');
} else
$greenwich = (int) gmdate('Gi');
if (($greenwich >= 1040) and ($greenwich <= 1055)) {
header('Location: http://intranet/time/one.htm');
} else
$greenwich = (int) gmdate('Gi');
if (($greenwich >= 1235) and ($greenwich <= 1310)) {
header('Location: http://intranet/time/one.htm');
} else
$greenwich = (int) gmdate('Gi');
if (($greenwich >= 1510) and ($greenwich <= 2359)) {
header('Location: http://intranet/time/one.htm');
} else {
header('Location: http://intranet/time/two.htm');
}
?>
But this doesn't seem to work. Also, I having trouble with time less than 1000. For example, where it should let students through between 1am and 8:55am just sends them to the error message. Would it work with 855 instead of 0855?
We're using PHP5 on our server if that helps.
Thanks