Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can I get a list of all active PHP sessions on a server and access them from within one user's instance?

The motivating case is displaying a list of all currently active users on the site, where usernames are stored in each user's PHP session.

Note: I know that I can create my own state via a database (or even the filesystem), but I'm looking for a way to utilize the built-in PHP session mechanisms.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
377 views
Welcome To Ask or Share your Answers For Others

1 Answer

Session List

<?php
print_r(scandir(session_save_path()));
?>

Check for a Specific Session

<?php
session_start();
echo (file_exists(session_save_path().'/sess_'.session_id()) ? 1 : 0);
?>

Time Session File Last Changed

<?php
session_start();
echo filectime(session_save_path().'/sess_'.session_id());
?>

As has been done to death, already, it isn't best-practice to handle sessions this way but if it's needed, those will work without the need to check/modify the session storage path (useful if you switch to another server with a different configuration).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...