What’s the difference? I know that session variables store information and let you use it across pages, but I’ve got a few questions: Where is the value stored? And what is the difference between a session variable and a normal variable?
This is in the context of PHP. I’m after an in-depth answer because I’ve not found alot of information about this online.
That depends on the PHP configuration. By default, session variables are serialized and written into a file on the server’s file system. On each page view that starts the session, they are unserialized and accessible from the
$_SESSIONarray. It’s possible to override the default session handler so that you can store the variables elsewhere, such as a database.Sessions work by storing a session ID (which is a unique identifier) as a cookie on the client’s computer. Each time the client requests a page, the session ID cookie is sent along with the request, PHP picks up the session ID from the cookie, and then pulls the sesssion data that relates to said session ID.
Simply put, a session variable gets saved to a source (such as file system), this is how they can persist between page requests. A normal variable will only live until the execution of the script completes, it will then be destroyed.