PHP Session Variables Scope

Viewed 23

Just want to understand how to implement this before I go through with it. This regards the scope of PHP session variables. I understand the concept of a 'session', of course, but what I am less clear about is whether that 'session' is global to all users of a web application (i.e. in which case if more than one user was accessing the PHP portion of a page at the same time they might start swapping/switching out variables on each other, which would not be good).

Or does a 'unique' session begin for every user every time the script is called ? In which case the 'sessions' would be isolated?

If 'session' is merely global for all users, all the time, I think I am likely better off using cookies or other methods to pass data between scripts, though the session variables method does seem so clean and tidy, otherwise.

1 Answers

Every user will get their own, unique session.

A visitor accessing your web site is assigned a unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL.

You should read more about sessions are their concept at the PHP documentation.

Related