1

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!

Nir Tzezana
  • 2,275
  • 3
  • 33
  • 56
  • 1
    Just to clear any confusion; PHP sessions are stored on the server side, and can only be read by the server, not the client. The Chrome add-ons you've been looking at will probably allow you to save and restore a list of open tabs, but that's not the kind of session you're looking for. – Patrickdev May 28 '13 at 11:11
  • You have session name = Cookie/Post/GET name. And variable name where session vars are stored. I don't know which one you mean. Can you please state what you would like to use this name for, so we can help you further ? – nl-x May 28 '13 at 11:35
  • Patrick is right. phpBB usage of $_SESSION is one that stores its own session data in the database. Have a look through includes/session.php and includes/startup.php which may help you understand how phpbb session works. – Damien Keitel May 28 '13 at 11:50
  • @nirTzezana is your question answered? – nl-x May 30 '13 at 17:39

5 Answers5

3

You can see the dump of $_SESSION variable

var_dump($_SESSION);
Anatoliy Gusarov
  • 797
  • 9
  • 22
3

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))

nl-x
  • 11,762
  • 7
  • 33
  • 61
1

try print_r ($_SESSION);

taht way you'll see all sessions

Touchpad
  • 662
  • 2
  • 12
  • 29
0
<?php 
session_start(); 
print_r($_SESSION);
?>

Use this to see which session variables are currently set.

Ryan
  • 3,552
  • 1
  • 22
  • 39
0

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

Community
  • 1
  • 1
Déjà vu
  • 28,223
  • 6
  • 72
  • 100