How does PHP get all the SessionID? Or get all the session

Source: Internet
Author: User
Just want to read all the SessionID through a. php file? Or get all the session??

Reply to discussion (solution)

Why is no one back??

Print_r ($_session);

Print_r ($_session);

I mean. Read all users, not single one.
For example, a user landed in a area to produce a SessionID B user landed in area B to produce a SessionID
Also get

All users need session database or even a session management system.
Google, have the results of previous efforts

Advanced usage of the session, write the session to the Memcache or database, you can achieve

Class Session {private static $handler =null;private static $ip =null;private static $lifetime =null;private static $time = null;//initialization variable, private static function init ($handler) {self:: $handler = $handler;//$_server["REMOTE_ADDR"] Get client routing Address ; Self:: $ip =!empty ($_server["REMOTE_ADDR"])? $_server["REMOTE_ADDR"]: ' Unknown ';//ini_get () Gets the configuration file variable; Self:: $lifetime =ini_get (' session.gc_maxlifetime '); $time =time ();} static function Start (PDO $pdo) {self::init ($PDO);//_class_ represents this 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::d Estroy ($PHPSESSID); return ';} if ($result ["update_time"] + self:: $lifetime) 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 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);

With this class

By default, if the file system is the driver, you can get the session file storage location by Session_save_path (). Then read each file sequentially and deserialize it.
Each user's session ID corresponds to a file, which begins with Sess_ and is stored in the location of the Session_save_path () lock setting.

This is not a good type.

Change the Session.save_handler to DB and then read the DB. But files are OK, so you should read the Session.save_path.

Echo session_id ()

All SessionID can only be read by the session's storage directory, or all sessions will be saved in the database.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.