You can see the dump of $_SESSION variable
var_dump($_SESSION);
Question
I installed a pre-built forum on my website and I want (in a diffrent page) to check if the forum's session is active.
Something like :
if (isset($_SESSION['forum'])) { echo "Session is active!"; }
Problem is - I don't know the sessions name... Tried downloading some chrome add-ons for session managing but I can't get the name of the session.
Whats the right way of doing this?
Thanks ahead!
Solution
You can see the dump of $_SESSION variable
var_dump($_SESSION);
OTHER TIPS
session_name()
will give you the session name, that usually is defined in php.ini. By default it is always: PHPSESSID
. This name is used as cookie name or as POST/GET variable name.
session_id()
will give you the identifier for the current session. It will be the contents of the cookie or POST/GET variable.
Then you have $_SESSION
that will contain all your session data. use print_r()
to see what you have stored in it so far.
To know if session vars are set you can also just do if(isset($_SESSION)&&count($_SESSION))
try
print_r ($_SESSION);
taht way you'll see all sessions
<?php
session_start();
print_r($_SESSION);
?>
Use this to see which session variables are currently set.
You need to check that the session is currently active, and then that the forum
key is defined
if ( ! ($sid = session_id()) {
session_start(); // open session if not yet opened
$sid = session_id(); // get sid as session ID
}
// $sid contains the session ID (in cookie)
if (isset($_SESSION['forum'])) {
// forum is defined
}
See also the answer from this page