array('127.0.0.1:11211'), 'debug' => false, 'compress_threshold' => 10240, 'persistant' => true)); $this->mc = $mc; return true; } public function close() { return true; } public function read($id) { return @$this->mc->get($id); } public function write($id, $data) { return $this->mc->set($id, $data, 30 * 60); } public function destroy($id) { $this->mc->delete($id); return true; } public function gc($maxlifetime) { return true; } } $handler = new FileSessionHandler(); session_set_save_handler( array($handler, 'open'), //告诉PHP引擎当用户开启session时运行open array($handler, 'close'), array($handler, 'read'), //高度PHP引擎,当用户读session时 array($handler, 'write'), //写session array($handler, 'destroy'), //销毁session array($handler, 'gc') ); // 下面这行代码可以防止使用对象作为会话保存管理器时可能引发的非预期行为 register_shutdown_function('session_write_close'); session_start(); // 现在可以使用 $_SESSION 保存以及获取数据了
发表评论