<?php
require_once("class_mysql.php");
class session
{
public $db;
function session(&$db)
{
$this -> db = &$db;
session_module_name('user');
session_set_save_handler(
array(&$this, 'open'),
array(&$this, 'close'),
array(&$this, 'read'),
array(&$this, 'write'),
array(&$this, 'destroy'),
array(&$this, 'gc')
);
session_start();
}
function unserialize($data_value)
{
$vars = preg_split('/([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\|/', $data_value, -1,
PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE
);
for ($i = 0; isset($vars[$i]); $i++)
{
$result[$vars[$i++]] = unserialize($vars[$i]);
}
return $result;
}
function open($path, $name)
{
return true;
}
function close()
{
return true;
}
function read($session_id)
{
$session_id = $this -> db -> escape_string($session_id);
if ($row = $this -> db -> query("select * from `sessions` where `session_id` = '$session_id' limit 1"))
{
return $row['data_value'];
}
else
{
$this -> db -> query("insert into `sessions` set `session_id` = '$session_id'");
return "";
}
}
function write($session_id, $data_value)
{
$data = $this -> unserialize($data_value);
$session_id = $this -> db -> escape_string($session_id);
$data_value = $this -> db -> escape_string($data_value);
$sql = "update `sessions` set ";
if (isset($data['user_id']))
{
$sql .= "`user_id` = '{$data['user_id']}', ";
}
$sql .= "`data_value` = '$data_value', "
. "`last_visit` = null "
. "where `session_id` = '$session_id'";
$this -> db -> query($sql);
return true;
}
function destroy($session_id)
{
$session_id = $this -> db -> escape_string($session_id);
$this -> db -> query("delete from `sessions` where `session_id` = '$session_id'");
return true;
}
function gc($lifetime)
{
$this -> db -> query("delete from `sessions`
where unix_timestamp(now()) - unix_timestamp(`last_visit`) > $lifetime");
return true;
}
// get sessions by user_id
function get($user_id)
{
$user_id = $this -> db -> escape_string($user_id);
return $this -> db -> query("select * from `sessions` where `user_id` = '$user_id'");
}
// get sessions list
function lists($page, $rows)
{
if ($page == 0)
{
return $this -> db -> query("select * from `sessions` order by `user_id`");
}
else
{
$start = ($page - 1) * $rows;
return $this -> db -> query("select * from `sessions` order by `user_id` limit $start, $rows");
}
}
}
?>以上就是session保存在mysql 的内容,更多相关内容请关注PHP中文网(www.php.cn)!
更新列表:1.求职列表后台审核了也显示不出来。2.点了职位后页面跳转不正确。3.首页点了人才简历页面你所在的位置标签不正确。4.点了职位后页面没有出现应聘此岗位标签。5.人才简历图片保存不下来。6.人才没有照片显示找不到路径的图片。7.首页资讯报错,and 附近有语法错误。8.资讯下面的热点资讯没有图片不显示无图出来。9.人才查看自己的职位列表表头显示不正确。10.人才的上传了图片,但是首页推荐信
0
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号