PDA

View Full Version : Redirect Based On Date AND Time



Zackeriney
12-21-2005, 03:54 PM
i want a code to redirect someone one different days and times when events are happening for example some times it would be a saturday at 12.15-5.15 i want them redirected and other times it may also be a wednesday night about 7.15-10.15. i want to be able to program these times in like says all the different saturdays wednesdys and sundays upto the end of each month so i dont have to keep modifying it, also after the 5.15 in my 1st example i would like it to not redirect just to stay on the page like normal. thanks zack

BLiZZaRD
12-26-2005, 09:17 AM
Not sure how much this will help... but it works for me:



<?php
if(date("H")<8)
header("location: /page.php")
?>


Obvisouly this is just a time redirect, but it does work with all php based time stamps, so all you need to do is throw in a couple if else statements with the date codes you need, and viola!

If you need more detailed ones I am sure Twey will be around soon ;)

Zackeriney
12-26-2005, 01:01 PM
Thanks but does anyone have a date code and if so would i just put

date code

time code?

thanks

BLiZZaRD
12-30-2005, 09:55 AM
You can find date codes HERE (http://us3.php.net/date)

An example of what you would need is this: (untested)



<?php
$a = date('G');
if($a < 6)
header("location: /page.php")
else if($a < 12)
header("location: /page2.php")
else if($a < 18)
header("location: /page3.php")
else header("location: /page4.php");
?>

Not sure exactly how to code that.. TWEY!!!!! Help out?? LOL

Twey
12-30-2005, 01:43 PM
Twey's had no internet for far too long, and had to resort to Lynx for the last couple of days. I hate wireless. :(

it would be a saturday at 12.15-5.15 i want them redirected and other times it may also be a wednesday night about 7.15-10.15.
This just involves a little arithmetic.
Try:

<?php
$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: wednesdaynight.php");
?>
Untested. Beware: your server may be in a different timezone to you...

mwinter
12-30-2005, 04:04 PM
header("Location: saturdayafternoon.php");It should be noted that the Location header requires an absolute URI (http://www.example.com/path/to/resource), not a relative one.

The documentation for the header function (http://uk.php.net/header) demonstrates how to do this dynamically, if necessary.

Mike

Twey
12-30-2005, 07:05 PM
Whoops. You corrected me on this before. Sorry, it slipped my mind.

lobiwan
10-08-2010, 01:44 PM
Supposed I wanted a particular page to load the first week of every month, but then for the remainder of the month, a different page? Any thoughts?
Thanks

djr33
10-08-2010, 06:22 PM
This discussion is five years old. Start a new one if you have a new question.