i'm trying set user registration system creates token expires after 48 hours (2 days). attempted program no avail. when test code error
a php error encountered
severity: error
message: class 'timedate' not found
filename: models/user_model.php
line number: 58
below code
public function istokenvalid($token) { $q = $this->db->get_where('tokens', array('token' => $token), 1); if($this->db->affected_rows() > 0){ $row = $q->row(); $created = $row->created; $createdts = strtotime($created); $expiredate = new timedate('y-m-d'); //$todayts = strtotime($today); $expiredate->add(new dateinterval('p2d')); if($createdts != $expiredate){ return false; } $user_info = $this->getuserinfo($row->user_id); return $user_info; }else{ return false; } }
you use strtotime()
assuming:
// timestamp token created $created = $row->created;
since token expire after 48 hours, need add 48 hours date variable $created
$expiredate = date("y-m-d h:i:s", strtotime($created . " + 48 hours"));
if want date part , not time, can omit h:i:s
can compare $expiredate
today's timestamp.
$today = date("y-m-d h:i:s"); if (strtotime($today) > strtotime($expire)) { echo "expired"; } else { echo "not yet"; }
Comments
Post a Comment