Display all users with $_SESSION[‘username’];

When we do this:

<?php
session_start();
echo $_SESSION['username'];
?>

We display our name, which is in the session.
And how to display all the names that are in the session?
And is it possible to shorten the session time at all?


Answer 1, authority 100%

The correct way is to write your own Session Handlerwhich will store all in some database (eg SQL). Then you will be able to make requests to all sessions, even for username, for anything


Answer 2

1) If I understand the question correctly, for each user action, write the date of the last action in the database. And in the output, you will only need to find users with activity in the last 5 (10, 15, …) minutes.
2) Specify in php settings:

php_value session.gc_maxlifetime __
php_value session.cookie_lifetime __

Or in script:

ini_set('session.gc_maxlifetime', __);
ini_set('session.cookie_lifetime', __);

Answer 3

print_r($_SESSION);
var_dump($_SESSION);
foreach($_SESSION as $value){echo $value;}

In my opinion, session files are killed by some script on linux in the /tmp folder


Answer 4

foreach($_SESSION as $key => $val) echo $key . "=" . $val . "<br>";

well, or you can try this in general

echo implode(',',$_SESSION);