我已经尝试了我能想到/找到的所有组合,无论我做什么,即使帐户没有被锁定,我的编码也会回复该信息:
<?php
$infosql = "SELECT * FROM premiersounds_users WHERE customer_id = $id";
$inforesult = mysql_query($infosql) or die(mysql_error());
$info = mysql_fetch_array($inforesult);
//Get current date from server
$format="%m/%d/%y";
$c_date=strftime($format);
//set sessions
$_SESSION['current_date'] = $c_date;
//The date in the database is 10/31/11
$_SESSION['lockout_date'] = $l_date;
//Check is Current date = lockout date
if ($c_date <= $l_date) {
header("location:documnet_editors/edit_weddingplanner.php?id=$id");
}
else {
echo 'Whoops! Were sorry your account has been locked to edits
because your event is less than 48 hours from now or your event has passed.
To make changes to your event please contact your DJ.';
}
?>
<?php
//Destroy Session for Lockout Date to prevent bypasses
unset($_SESSION['lockout_date']);
?>
答案 0 :(得分:0)
如果您的$ l_date已填充,我认为不是,如果它存储为MM / DD / YY,您将需要使用PHP的strtotime将其转换为unix时间戳以进行快速比较:< / p>
if( strtotime($db_date) >= time() )
{
// do something
}
答案 1 :(得分:0)
将您的日期转换为unixtime以进行更准确的比较。将此函数添加到您的代码中:
function unix_time($date){
$unix_date = str_replace("-","/",$date);
$unix_date = str_replace(".","/",$unix_date);
$unix_date = str_replace(" pm","",$unix_date);
$unix_date = str_replace(" am","",$unix_date);
$time = strtotime($unix_date);
return $time;
}
然后将日期转换为unix:
$l_date = unix_time($_SESSION['lockout_date']);
$c_date = unix_time($_SESSION['current_date']);
或者您也可以直接从数据库中获取日期:
$l_date = unix_time($info['date_in_database']);
比较unix格式的日期:
if ($c_date = $l_date) {
// your code here
}
这应该有效。
答案 2 :(得分:0)
我建议比较时间戳而不是格式化日期:
<?php
$date_a = new DateTime();
$date_b = new DateTime('2000-10-20 00:10:20');
if ($date_a->getTimestamp() > $date_b->getTimestamp()) {
echo 1;
} else {
echo 0;
}