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

Source: Internet
Author: User
How does PHP get all the SessionID? Or get all the session


Just want to read all the SessionID through a. php file? Or get all the session??
Session PHP


------Solution--------------------
Why is no one back??
------Solution--------------------
Print_r ($_session);
------Solution--------------------
All users need session database or even a session management system.
Google, have the results of previous efforts
------Solution--------------------
Advanced usage of the session, write the session to the Memcache or database, you can achieve
------Solution--------------------
Class Session {
private static $handler =null;
private static $ip =null;
private static $lifetime =null;
private static $time =null;
Initialize variables;
private static function init ($handler) {
Self:: $handler = $handler;
$_server["REMOTE_ADDR"] Gets the 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 ');
Self:: $time =time ();
}

static function Start (PDO $pdo) {
Self::init ($PDO);
_class_ represents this category;
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) < self:: $time) {
Self::d Estroy ($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 (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.