0

When you set a Boolean session variable when a user logs in in PHP like:

$_SESSION['logged_in'] = true;

Since this session variable is a Boolean and not a number, and Session variables are stored onto the server not the user Computer, I expect that any browser(user) visiting that site where somebody(another browser) has already logged in, should automatically be logged in since the session variable has a Boolean value of true and not a unique number for different users and has already being set on the server.

How does the server identifies that a particular browser has not visited the site even though a Boolean Session has been set.

ultrasamad
  • 368
  • 4
  • 16
  • 2
    Possible duplicate of [How do PHP sessions work? (not "how are they used?")](http://stackoverflow.com/questions/1535697/how-do-php-sessions-work-not-how-are-they-used) – Jez Emery Jan 05 '17 at 11:44

2 Answers2

0

I think this will answer your question How do PHP sessions work? (not "how are they used?")

tldr; In the general situation :

  • the session id is sent to the user when his session is created.
  • it is stored in a cookie (called, by default, PHPSESSID)
  • that cookie is sent by the browser to the server with each request
  • the server (PHP) uses that cookie, containing the session_id, to know which file corresponds to that user.
Community
  • 1
  • 1
Jez Emery
  • 676
  • 4
  • 18
0

Sessions are unique per browser, not per computer / IP and so on. The browser will store a so called session cookie which will send back to the server with every request, allowing the server to identify the user. Every time you store something in the $_SESSION super global, this value is recorded in the current user's session, which is not available to others.

Further reading: http://php.net/manual/en/book.session.php

motanelu
  • 3,945
  • 1
  • 14
  • 21