Php 在带有checkdate的特定日期加载页面,如果不重定向页面,请将其重定向

Php 在带有checkdate的特定日期加载页面,如果不重定向页面,请将其重定向,php,Php,我想,我的页面只能在特定日期加载。如果没有,请重定向另一个。我发现,checkdate可以实现这一点,但作为一名php新手,我不知道该怎么做。 它应该简单到: 检查日期->有效->加载页面 checkdate->invalid->重定向到example.php 有人能把我推向正确的方向吗? 提前谢谢 函数isValidDate($sd,$ed,$currentDate=null) function isValidDate($sd, $ed, $currentDate = null) {

我想,我的页面只能在特定日期加载。如果没有,请重定向另一个。我发现,checkdate可以实现这一点,但作为一名php新手,我不知道该怎么做。 它应该简单到: 检查日期->有效->加载页面 checkdate->invalid->重定向到example.php 有人能把我推向正确的方向吗? 提前谢谢

函数isValidDate($sd,$ed,$currentDate=null)
function isValidDate($sd, $ed, $currentDate = null)
{
    if ($currentDate === null) {
        $currentDate = date('Y-m-d');
    }

    return ($currentDate >= $sd && $currentDate <= $ed);
}

$startDate = 'yyyy-mm-dd';
$endDate   = 'yyyy-mm-dd';
if (isValidDate($startDate, $endDate)) {
    // show page
} else {
    // redirect to example.php
}
{ 如果($currentDate==null){ $currentDate=日期('Y-m-d'); } 返回($currentDate>=$sd&&$currentDate)