<?php
session_start();
echo "<h3> PHP List All Session Variables</h3>";
foreach ($_SESSION as $key=>$val)
echo $key." ".$val."<br/>";
?>
You could use the following code.
print_r($_SESSION);
Not a simple way, no.
Let's say that by "active" you mean "hasn't passed the maximum lifetime" and hasn't been explicitly destroyed and that you're using the default session handler.
If you really need this, you must implement some sort of custom session handler. See session_set_save_handler
.
Take also in consideration that you'll have no feedback if the user just closes the browser or moves away from your site without explciitly logging out. Depending on much inactivity you consider the threshold to deem a session "inactive", the number of false positives you'll get may be very high.
this worked for me:-
<?php echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>'; ?>
thanks for sharing code...
Array
(
[__ci_last_regenerate] => 1490879962
[user_id] => 3
[designation_name] => Admin
[region_name] => admin
[territory_name] => admin
[designation_id] => 2
[region_id] => 1
[territory_id] => 1
[employee_user_id] => mosin11
)
Echo the session object as json. I like json because I have a browser extension that nicely formats json.
session_start();
echo json_encode($_SESSION);
session_start();
echo '<pre>';var_dump($_SESSION);echo '</pre>';
// or
echo '<pre>';print_r($_SESSION);echo '</pre>';
NOTE: session_start(); line is must then only you will able to print the value $_SESSION
Source: Stackoverflow.com