<?php /** * session类 * @author 角度 QQ:1286522207 * */ class session extends Action{ private $session_db; private $session_Overdue; private $db_tablename;//数据库名称 function __construct(){ $this->session_Overdue=3600; $this->session_db= $this->db(); } /** * 打开 */ public function open() { return true; } /** * 关闭 */ public function close() { return true; } /** * 读取 */ public function read($id) { $where['id']=$id; $this->session_db->M('session'); $value=$this->session_db->find($where); if ($value) { return $value['data']; } else { return ""; } } /** * 写入 */ public function write($id, $datas) { $where['id']=$id; $date['data']=$datas; $date['time']=time()+$this->session_Overdue; $date['ip']=$this->session_db->get_client_ip(); if (empty($_SESSION['user_id'])){ $date['user']=0; }else { $date['user']=$_SESSION['user_id']; } $this->session_db->M('session'); $up=$this->session_db->Update($date, $where); if ($up){ return true; }else { $date['id']=$id; $this->session_db->Insert($date); return true; } } /** * 摧毁 */ public function destroy($id) { $where['id']=$id; return $this->session_db->Delete($where); } /** * 回收 */ public function gc($max) { return true; } function __destruct(){ $this->session_db->Delete("`time`<'".time()."'"); } } ini_set ( 'session.save_handler',$config['SESSION_START']); $session = new session (); session_set_save_handler ( array ($session, 'open' ), array ($session, 'close' ), array ($session, 'read' ), array ($session, 'write' ), array ($session, 'destroy' ), array ($session, 'gc' ) ); session_start();