dongwenhui8900 2017-06-26 18:59 采纳率: 0%
浏览 35

时间相关的URL重定向脚本无法正常工作

This is the top part of a script I am using for redirection. It connects to two txt based databases depending on time and redirects the user to a particular link. There are two databases 'db1.txt' and 'db2.txt', It should be using only the 'db2.txt' on Sundays. It should use the 'db1.txt' Monday-Saturday 9AM to 6PM and It should use the 'db2.txt' Monday-Saturday 6:01PM to 8:59AM but now here in India, time is 12.26AM, and it is still using 'db1.txt' instead of 'db2.txt' How to fix it ?

date_default_timezone_set('Asia/Kolkata');
$time = date("Hi", time());
##
if (date('N') !=7 && $time >= 0900 && $time <= 1800)
{
    $db = "db1.txt";
}
else
{
    $db = "db2.txt";
}
  • 写回答

1条回答 默认 最新

  • douzhan2027 2017-06-26 19:13
    关注

    I believe your leading zeros are messing up the comparison, use this instead:

    date_default_timezone_set('Asia/Kolkata');
    $time = date("G");
    ##
    if (date('N') !=7 && $time >= 9 && $time < 18)
    {
        $db = "db1.txt";
    }
    else
    {
        $db = "db2.txt";
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能