摘要:调用调用执行完毕调用获取数据调用赋值调用调用过期调用
</>复制代码
class FileSessionHandler implements SessionHandlerInterface
{
private $savePath;
/**
* 调用 session_start 调用
*
* @param string $savePath
* @param string $sessionName
* @return bool
*/
function open($savePath, $sessionName)
{
echo "open.
";
$this->savePath = $savePath;
if (!is_dir($this->savePath)) {
mkdir($this->savePath, 0777);
}
return true;
}
/**
* session 执行完毕调用
*
* @return bool
*/
function close()
{
echo "close.
";
return true;
}
/**
* 获取session数据调用
*
* @param string $id
* @return string
*/
function read($id)
{
echo "read.
";
return (string)@file_get_contents("$this->savePath/sess_$id");
}
/**
* session赋值调用
*
* @param string $id
* @param string $data
* @return bool
*/
function write($id, $data)
{
echo "write.
";
return file_put_contents("$this->savePath/sess_$id", $data) === false ? false : true;
}
/**
* 调用session_destory
*
* @param string $id
* @return bool
*/
function destroy($id)
{
echo "destroy.
";
$file = "$this->savePath/sess_$id";
if (file_exists($file)) {
unlink($file);
}
return true;
}
/**
* 过期调用
*
* @param int $maxlifetime
* @return bool
*/
function gc($maxlifetime)
{
echo "gc.
";
foreach (glob("$this->savePath/sess_*") as $file) {
if (filemtime($file) + $maxlifetime < time() && file_exists($file)) {
unlink($file);
}
}
return true;
}
}
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/31709.html
摘要:为应用程序启用会话状态时,将检查应用程序中每个页面请求是否有浏览器发送的值。如果未提供任何值,则将启动一个新会话,并将该会话的值随响应一起发送到浏览器。 session 什么是session? session在计算机中,尤其在网络应用中,称为会话控制;具体到web中的session指的就是用户在浏览某个网站时,从进入网站到浏览器关闭所经过的这段时间,也就是用户浏这个网站所花费的时间。...
摘要:的作用就是为了解决协议无状态的缺陷所作的努力。的内容主要包括名字,值,过期时间,路径和域。这种生命期为浏览器会话期的被称为会话。而机制采用的是一种在服务器端保持状态的解决方案。中的有效期默认分钟,也就是说,客户端超过分钟,当前就会失效。 会话控制是什么? cookie和session都是跟踪整个会话过程的技术手段。而会话,就是用户通过浏览器和服务器的一次通话。 为什么要有会话控制? 因...
摘要:服务器给访问者唯一的钥匙,这个钥匙被称作。与合起来用来管理垃圾回收进程启动的概率。例如意味着在每个请求中有的概率启动进程。值为表示直到关闭浏览器。过期时间设置为秒启动概率设置为 什么是 Session 在 web 应用开发中,Session 被称为会话。主要被用于保存某个访问者的数据。由于 HTTP 无状态的特点,服务端是不会记住客户端的,对服务端来说,每一个请求都是全新的。既然如此,...
阅读 3381·2021-11-19 09:40
阅读 3124·2021-09-09 09:32
阅读 918·2021-09-02 09:55
阅读 1501·2019-08-26 13:23
阅读 2578·2019-08-26 11:46
阅读 1342·2019-08-26 10:19
阅读 2186·2019-08-23 16:53
阅读 1177·2019-08-23 12:44