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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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");
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.