<?php class usrtoken { public int $tid=-1; public int $user_id=-1; //-1为无数据 public string $token; public int $expireon; #--comment '过期时刻的timestamp', public function insert(SQLite3 & $sqlitehanle) { //var_dump($this); $sql='insert into usrtoken(user_id,token,expireon)values(' .$this->user_id .'\''.$this->token.'\'' .$this->expireon.');'; $sqlitehanle->exec($sql); } public function reset() { $this->tid=-1; $this->user_id=-1; $this->token=''; $this->expireon=-1; } public function readfromsqlite(SQLite3 & $sqlitehanle,string $token) { $sql=//'attach database \'redbit.db\' as redbit;' 'select tid,user_id,token,expireon from usrtoken where token=\''.$token.'\';'; //.'detach database \'redbit\';'; //'attach database \'redbit.db\' as redbit;' //print($sql."\n"); $tmp=$sqlitehanle->query($sql); //var_dump($tmp); $rst=$tmp->fetchArray(SQLITE3_ASSOC); if($tmp!=false && $rst!=null) { $this->tid=$rst['tid']; $this->user_id=$rst['user_id']; $this->token=$rst['token']; $this->expireon=$rst['expireon']; } return $rst; } } function registutoken(SQLite3 & $sqlitehanle,$user_id,$expireon) { $token=md5($user_id.$expireon.rand(1,9999)); $sql='insert into usrtoken(user_id,token,expireon)values(' .$user_id .',\''.$token.'\',' .$expireon.');'; $sqlitehanle->exec($sql); return $token; } function checkdue(SQLite3 & $sqlitehanle,string $token) { $sql=//'attach database \'redbit.db\' as redbit;' 'select expireon from usrtoken where token=\''.$token.'\';'; //.'detach database \'redbit\';'; //'attach database \'redbit.db\' as redbit;' //print($sql."\n"); $tmp=$sqlitehanle->query($sql); //var_dump($tmp); $expireon=$tmp->fetchArray(SQLITE3_INTEGER); if($expireon!=null) { if($expireon>=time()) return true; } return false; } ?>