会员系统登录占用保护,如何实现? 一会员系统,有一共享账号,希望实现某用户登录后,其他的用户无法登录。退出时候,必须点击退出,解锁。目前是用某字段来实现。登录为1,退出为0.但是在退出机制中,有时候会员被意外停电,无法实现正常注销。。 或者忘记注销等情况, 请问如何解决类似问题。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 官方网站给出的例子,红色的需要你追加自己的代码。<?phpclass FileSessionHandler{ private $savePath; function open($savePath, $sessionName) { $this->savePath = $savePath; if (!is_dir($this->savePath)) { mkdir($this->savePath, 0777); } return true; } function close() { return true; } function read($id) { return (string)@file_get_contents("$this->savePath/sess_$id"); } function write($id, $data) { return file_put_contents("$this->savePath/sess_$id", $data) === false ? false : true; } function destroy($id) { $file = "$this->savePath/sess_$id"; if (file_exists($file)) { $data = unserialize($this->read($id)); mysql_query("UPDATE user SET status = 1 WHERE user_id = ".$data['user_id']); unlink($file); } return true; } function gc($maxlifetime) { foreach (glob("$this->savePath/sess_*") as $file) { if (filemtime($file) + $maxlifetime < time() && file_exists($file)) { $data = unserialize($this->read(str_replace("sess_", $file))); mysql_query("UPDATE user SET status = 1 WHERE user_id = ".$data['user_id']); unlink($file); } } return true; }}$handler = new FileSessionHandler();session_set_save_handler( array($handler, 'open'), array($handler, 'close'), array($handler, 'read'), array($handler, 'write'), array($handler, 'destroy'), array($handler, 'gc') );// the following prevents unexpected effects when using objects as save handlersregister_shutdown_function('session_write_close');session_start();?> 退出为0的话,上面的例子应该是status = 0。另外如果退出处理里已经修改status=0的话,destroy函数可以不用改。gc处理有超时时间,非正常退出的场合,默认要等1440秒,这个时间可以设置ini_set('session.gc_maxlifetime', 600)。 php 服务器推送问题。 请教WAP开发中的乱码问题 211.99.5.173每天访问我的博客多达30-40次,这是个什么地址? 这个生成所略图怎么不行呢?? PHP正则问题 高手请帮忙,如何去除重复的值?? 上传文件问题:2K下可以,98下出错 一个奇怪的问题,请大家多多指教 天那,这样也会错?$mydb[$i][fair_type_name] PHP关于AJAX一点疑惑 加载php5.3.1后apache2_2无法重启! 麻烦各位帮个忙解密一下php加密代码
官方网站给出的例子,红色的需要你追加自己的代码。<?php
class FileSessionHandler
{
private $savePath; function open($savePath, $sessionName)
{
$this->savePath = $savePath;
if (!is_dir($this->savePath)) {
mkdir($this->savePath, 0777);
}
return true;
} function close()
{
return true;
} function read($id)
{
return (string)@file_get_contents("$this->savePath/sess_$id");
} function write($id, $data)
{
return file_put_contents("$this->savePath/sess_$id", $data) === false ? false : true;
} function destroy($id)
{
$file = "$this->savePath/sess_$id";
if (file_exists($file)) {
$data = unserialize($this->read($id));
mysql_query("UPDATE user SET status = 1 WHERE user_id = ".$data['user_id']);
unlink($file);
} return true;
} function gc($maxlifetime)
{
foreach (glob("$this->savePath/sess_*") as $file) {
if (filemtime($file) + $maxlifetime < time() && file_exists($file)) {
$data = unserialize($this->read(str_replace("sess_", $file)));
mysql_query("UPDATE user SET status = 1 WHERE user_id = ".$data['user_id']);
unlink($file);
}
}
return true;
}
}$handler = new FileSessionHandler();
session_set_save_handler(
array($handler, 'open'),
array($handler, 'close'),
array($handler, 'read'),
array($handler, 'write'),
array($handler, 'destroy'),
array($handler, 'gc')
);// the following prevents unexpected effects when using objects as save handlers
register_shutdown_function('session_write_close');session_start();
?>