View Full Version : Redirect Based On Date AND Time
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
12-26-2005, 09:17 AM
Not sure how much this will help... but it works for me:
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 ;)
12-26-2005, 01:01 PM
Thanks but does anyone have a date code and if so would i just put
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)
$a = date('G');
if($a < 6)
else if($a < 12)
else if($a < 18)
else header("location: /page4.php");
Not sure exactly how to code that.. TWEY!!!!! Help out?? LOL
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.
$hour = date('G');
$minute = date('i');
$day = date('w');
$m = $hour * 60 + $minute; // Minutes since midnight.
$day == 6 // Saturday...
&& $m >= 735 // ... after 12:15...
&& $m <= 1035 // ... but before 17:15...
) header("Location: saturdayafternoon.php");
$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...
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.
Whoops. You corrected me on this before. Sorry, it slipped my mind.
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?
10-08-2010, 06:22 PM
This discussion is five years old. Start a new one if you have a new question.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.