26

I have the session id of my application. now i want to get all the session variables by using this session id.

I used <?php echo session_id()?> to get the session id but how to get all the session object values by using this session id?

Mohammed H
  • 6,880
  • 16
  • 81
  • 127
Manish Jangir
  • 5,329
  • 4
  • 42
  • 75

4 Answers4

68

According to php.net: There are several ways to leak an existing session id to third parties. A leaked session id enables the third party to access all resources which are associated with a specific id. First, URLs carrying session ids. If you link to an external site, the URL including the session id might be stored in the external site's referrer logs. Second, a more active attacker might listen to your network traffic. If it is not encrypted, session ids will flow in plain text over the network. The solution here is to implement SSL on your server and make it mandatory for users.

This begs the question, how do you have the session ID but unable to access the script?

Regardless, you would need to set the session ID and then start it...then access the data.

session_id($whatever_id_you_have);
session_start();
echo $_SESSION['somekey'];
Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133
  • 10
    +1 Only this answer says how to get session data using session_id. – Mohammed H Apr 10 '13 at 05:31
  • 2
    When session.use_strict_mode is set to 1 or true, you cannot use session_id($sid) to set the session id for the current session. http://php.net/manual/en/function.session-id.php – Autumn Leonard Jan 26 '17 at 17:35
2

You can check all session value using this one..

print_r($_SESSION);
2

$_SESSION is what you are looking for. Remember to call session_start() first. See http://php.net/session.examples.basic

KingCrunch
  • 128,817
  • 21
  • 151
  • 173
2

var_dump($_SESSION); will show you the contents of the current session, you can then access the values just like you would on a normal array.

Tatu Ulmanen
  • 123,288
  • 34
  • 187
  • 185