我有3个索引文件
index1.php
night.php
weekend.php
我想使用特定时间示例使用index.php中的重定向页面访问night.php:每小时3.00pm index.php重定向到night.php,每小时7.30am再次返回index.php页面< / p>
请帮助!!
答案 0 :(得分:0)
Hope this will help you!!!
date_default_timezone_set('Australia/Adelaide'); //Sets the default timezone
$time = strtotime(date("h", time()));
if($time ==strtotime("15:20:00")){
header("location: night.php");
exit;
}
if($time==strtotime("7:30:00")){
header("location: index.php");
exit;
}
`
答案 1 :(得分:0)
利用PHP的date
函数检查当前时间/日期。要重定向到另一个文件,只需使用header("Location: ..")
功能进行302重定向。
以下是我可以从您的需求说明中了解的快速示例:
<?php
$redirectLocation = '';
$dayOfWeek = date('l'); // A full textual representation of the day of the week
$weekendDays = array('Saturday', 'Sunday'); // Array of weekend days
$currentTime = (date('G').date('i'))*1; // Get current time in the form of numbers
// If is weekend, redirect to weekend.php
if(in_array( $dayOfWeek, $weekendDays )) {
$redirectLocation = 'weekend.php';
}
// Else handle weekday day time (7.30 - 15.00)
else if( $currentTime >= 730 && $currentTime <= 1500 ) {
$redirectLocation = 'index1.php';
}
// Else handle weekday evening time
else {
$redirectLocation = 'night.php';
}
// Do the redirecting
header("Location: ".$redirectLocation);
exit();
?>