Jump to content

redirect based on time


jiggles

Recommended Posts

Hi,

 

Just having some problems executing this script. Can someone see what I am doing wrong ?

 

Thanks in advanced

 

<?php
$time = date("Hi"); //returns HoursMinutes
if( ($time >= "0000" && $time < "0000") || ($time >= "0000" && $time < "0000") || ($time >= "0000" && $time < "0000") )
{
header("Location: REDIRECT URL");
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/185845-redirect-based-on-time/
Share on other sites

Basically but what is with your OR and AND statements? You're saying if the date is larger than 0, equal to 0, or greater than 0 it'll redirect. Doesn't matter what you replace the time with, it'll always run. You need to use IF/ELSE's the proper way, if you want an example tell us more what you're trying to do and we'd be glad to write you one.

Hi,

 

Thanks for your quick response. I just wanted to between the times (server time) 7:00am-9:00am & 5.00pm-7.00pm to do nothing so they can access that certain page.

 

Any other times it will redirect the user back out to the main page index.php.

 

So, I was going to have >"0000"  && <"7000"  || >"9000" <"1700" etc... for the other times to do a redirect.

Is something like this more suitable ?

 

<?php
$time = date("Hi"); //returns Hours & mins
if($time >= 0000 && $time <= 0700) header("Location: http://www.something.index.php");
else if($time >= 0900 && $time <= 1700) header("Location: http://www.something.index.php");
else if($time >= 1900 && $time <= 2359) header("Location: http://www.something.index.php");
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.