Reputation: 311
I'm using this code to redirect based on the hour of the day, and the day of the week.
Here it is ..
<?php
$hour = date('G');
$minute = date('i');
$day = date('w');
$m = $hour * 60 + $minute; // Minutes since midnight.
if (
$day == 0 // Sunday...
&& $m >= 615 // ... after 10:15…
&& $m <= 700 // ... but before 11:40…
) {
header("Location: open.php");
}
else
if (
$day == 3 // Wednesday...
&& $m >= 1125 // ... after 18:45…
&& $m <= 1235 // ... but before 20:35…
) {
header("Location: open.php");
}
?>
I was wondering if there was a way to redirect to a page based on an exact date in the future like April 25th or November 1st.
Thanks .
Upvotes: 0
Views: 3016
Reputation: 14502
This is a simple approach, which does not take account the year date:
// 25th april:
if (date('d') == '25' && date('m') == '4') {
header('Location: open.php');
}
// 1st nov:
if (date('d') == '1' && date('m') == '11') {
header('Location: open.php');
}
Look at the date() documentation for more exact details.
Upvotes: 2
Reputation: 6389
Sure.
$date = date();
$redirectDate = Date here;
if($date == $redirectDate) {
header("Location: open.php");
}
This is going to be based on your server date/time
Upvotes: 1
Reputation: 78991
Convert the redirection date into timestamp using strtotime()
or date()
and you can do it easily
if(strtotime("2012/5/3") <= time()) {
header("location: toredirect.php");
exit;
}
Upvotes: 1