<?phpnamespace Lib;class Session{private $mypdo;public function __construct() {session_set_save_handler([$this,'open'],[$this,'close'],[$this,'read'],[$this,'write'],[$this,'destroy'],[$this,'gc']);session_start();}public function open() {$this->mypdo= \Core\MyPDO::getInstance($GLOBALS['config']['database']);return true;}//关闭会话public function close() {return true;}//读取会话public function read($sess_id) {$sql="select sess_value from sess where sess_id='$sess_id'";return (string)$this->mypdo->fetchColumn($sql);}//写入会话public function write($sess_id,$sess_value) {$sql="insert into sess values ('$sess_id','$sess_value',unix_timestamp()) on duplicate key update sess_value='$sess_value',sess_time=unix_timestamp()";return $this->mypdo->exec($sql)!==false;}//销毁会话public function destroy($sess_id) {$sql="delete from sess where sess_id='$sess_id'";return $this->mypdo->exec($sql)!==false;}//垃圾回收public function gc($lifetime) {$expires=time()-$lifetime; //过期时间点$sql="delete from sess where sess_time<$expires";return $this->mypdo->exec($sql)!==false;}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。