解决方案 »

  1.   


    我的意思是。读取所有用户,不是单一个。
    比如A用户在A地区登陆产生一个SESSIONID  B用户在B地区登陆产生一个SESSIONID 
    同时获取
      

  2.   

    所有的用户需要session数据库甚至一个session管理系统
    google一下,有前人努力的成果
      

  3.   

    session的高级用法,把session写到memcache或数据库里,就可以实现了
      

  4.   

    class Session {
    private static $handler=null;
    private static $ip=null;
    private static $lifetime=null;
    private static $time=null;
    //初始化变量;
    private static function init($handler){
    self::$handler=$handler;
    //$_SERVER["REMOTE_ADDR"]获取客户端路由地址;
    self::$ip = !empty($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : 'unknown';
    //ini_get()获取配置文件变量;
    self::$lifetime=ini_get('session.gc_maxlifetime');
    self::$time=time();
    } static function start(PDO $pdo){
    self::init($pdo);
    //_CLASS_  代表本类;
    session_set_save_handler(
    array(__CLASS__,"open"),
    array(__CLASS__,"close"),
    array(__CLASS__,"read"),
    array(__CLASS__,"write"),
    array(__CLASS__,"destroy"),
    array(__CLASS__,"gc")
    ); session_start();
    } public static function open($path, $name){
    return true;
    } public static function close(){
    return true;
    }

    public static function read($PHPSESSID){
    $sql="select PHPSESSID, update_time, client_ip, data from session where PHPSESSID= ?"; $stmt=self::$handler->prepare($sql); $stmt->execute(array($PHPSESSID));

    if(!$result=$stmt->fetch(PDO::FETCH_ASSOC)){
    return '';
    } if( self::$ip  != $result["client_ip"]){
    self::destroy($PHPSESSID);
    return '';
    } if(($result["update_time"] + self::$lifetime) < self::$time ){
    self::destroy($PHPSESSID);
    return '';
    } return $result['data']; } public static function write($PHPSESSID, $data){
    $sql="select PHPSESSID, update_time, client_ip, data from session where PHPSESSID= ?"; $stmt=self::$handler->prepare($sql); $stmt->execute(array($PHPSESSID)); if($result=$stmt->fetch(PDO::FETCH_ASSOC)){
    if($result['data'] != $data || self::$time > ($result['update_time']+30)){
    $sql="update session set update_time = ?, data =? where PHPSESSID = ?";

    $stm=self::$handler->prepare($sql);
    $stm->execute(array(self::$time, $data, $PHPSESSID));

    }
    }else{
    if(!empty($data)){
    $sql="insert into session(PHPSESSID, update_time, client_ip, data) values(?,?,?,?)"; $sth=self::$handler->prepare($sql); $sth->execute(array($PHPSESSID, self::$time, self::$ip, $data));
    }
    } return true;
    } public static function destroy($PHPSESSID){
    $sql="delete from session where PHPSESSID = ?"; $stmt=self::$handler->prepare($sql); $stmt->execute(array($PHPSESSID)); return true;
    } private static function gc($lifetime){
    $sql = "delete from session where update_time < ?"; $stmt=self::$handler->prepare($sql); $stmt->execute(array(self::$time-$lifetime)); return true;
    }
    } try{
    $pdo=new PDO("mysql:host=localhost;dbname=xsphpdb", "root", "123456");
    }catch(PDOException $e){
    echo $e->getMessage();
    } Session::start($pdo);用这个类
      

  5.   

    默认的,如果是以文件系统来驱动,你可以通过 session_save_path() 来获取session文件的存储位置。然后依次读取每个文件并反序列化。每个用户的session id对应一个文件,这个文件以 sess_ 开头,存储在 session_save_path() 锁设定的位置。
      

  6.   

    将session.save_handler改成db,然后去读那个db。不过files也可以,那你就去读session.save_path下的文件吧。
      

  7.   

    所有的sessionid只能通过session的存储目录来读取的,或者将所有session保存在数据库。