How does php obtain all sessionids? Or retrieve all sessions.

Source: Internet
Author: User
How does php obtain all sessionids? Or get all sessions & nbsp; is to read all & nbsp; sessionid & nbsp; through a. php file ;? Or get all sessions & nbsp ;?? How does session php obtain all sessionids? Or retrieve all sessions.
 

Is it to read all sessionids through A. php file? Or get all sessions ??
Session php
------ Solution --------------------
Why is there no response ??
------ Solution --------------------
Print_r ($ _ SESSION );
------ Solution --------------------
All users need a session database or even a session management system.
Google, with the achievements of our predecessors
------ Solution --------------------
The advanced usage of the session can be achieved by writing the session to memcache or database.
------ Solution --------------------
Class Session {
Private static $ handler = null;
Private static $ ip = null;
Private static $ lifetime = null;
Private static $ time = null;
// Initialize the variable;
Private static function init ($ handler ){
Self: $ handler = $ handler;
// $ _ SERVER ["REMOTE_ADDR"] obtain the route address of the client;
Self: $ ip =! Empty ($ _ SERVER ["REMOTE_ADDR"])? $ _ SERVER ["REMOTE_ADDR"]: 'Unknown ';
// Ini_get () get the configuration file variable;
Self: $ lifetime = ini_get ('session. gc_maxlifetime ');
Self: $ time = time ();
}

Static function start (PDO $ pdo ){
Self: init ($ pdo );
// _ CLASS _ indicates 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: 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
------ Solution --------------------
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 (?,?,?,?) ";

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.