0

可以做一些帮助。所以我有一个只能在两个日期之间访问的网站。在我的数据库中,我有以下内容

Name       Type            Data   
start_date VARCHAR(255)  - 11/01/2012
start_time VARCHAR(255)  - 14:32
end_date   VARCHAR(255)  - 13/01/2012
end_time   VARCHAR(255)  - 17:20

我只需要只允许在上述日期访问用户。这是我正在使用的代码,但它似乎不起作用我做错了什么吗?我正在运行 PHP4

$current_date = strtotime(date("Y-m-d H:i:s"));

//db query and while loop here

$start_date = explode("/", $rows['start_date']);
$start_time = $rows['start_time'];
$start_date = strtotime($start_date[2] . "-" . $start_date[1] . "-" . $start_date[0] . " " . $start_time); 


$end_date = explode("/", $rows['end_date']);
$end_time = $rows['end_time'];
$end_date = strtotime($end_date[2] . "-" . $end_date[1] . "-" . $end_date[0] . " " .  $end_time);


if(($current_date <= $start_date) || (($current_date >= $end_date)))
{
    echo "Site can only be access between" . $start_date . " and " . $end_date;
}
else 
{
    // redirect to the site...
}

提前致谢 :)

4

0 回答 0