之間的差異我已經創建了註冊頁面,當用戶單擊提交按鈕時,激活鏈接被髮送到他的電子郵件,因此時間戳存儲在數據庫中。如果用戶點擊激活鏈接,我必須在24小時之前或之後檢查該鏈接是否被點擊。 我的代碼: -計算時間戳
function confirmEmail($activation_code){
$this->load->database();
$this->load->helper('date');
echo "activation link will be checked and accordingly flag will be set.";
$activation_sent_timestamp=$this->db->query("SELECT activation_timestamp FROM tbl_user_registration WHERE email_verification_code='$activation_code'");
foreach($activation_sent_timestamp->result() as $res){
$activation_time_from_db=$res->activation_timestamp;
}
echo $activation_time_from_db."\n\r";
$now = time();
$human = unix_to_human($now);
echo $human;
$difference = ($human-$activation_time_from_db);
if($difference < 24) {
echo "correct"
}
else echo "Link expired";
}
我正在使用codeigniter。我怎麼能這樣做,這段代碼沒有顯示任何錯誤,但我不知道這是計算24小時的正確方法,我正在檢查,但沒有得到任何東西。請檢查代碼。
解決........ :)
建議:我總是儘量保持PHP的日期和MySQL的日期分開,因爲有時存在不匹配。如果您使用NOW()插入數據,則在INTERVAL 1天內使用DATE_ADD和DATE_SUB。如果field是datetime,則使用UNIX_TIMESTAMP()將其轉換。如果您插入'time()',則可以使用strtotime('+ 1 day')。 – Waygood