User Sessions
Learn what sessions are, how to use them in PHP, and how to avoid common session-related pitfalls.
Let’s look at another data storage mechanism—user sessions. They’re more stable than cache, but they have short-term persistence too.
What are user sessions?
Sessions are a data store for short-term user-specific data. For example, imagine Alice opens a website and logs in. The information that stores the fact she has logged in as a specific user needs to be preserved across multiple requests, so she stays logged in after refreshing the page. This information is short-term—if she opens the same website the next day, she’ll have to log in again. And, this information is user-specific, so if Bob opens the same website on another computer, he won’t be logged in as Alice. Take a second to admire how great that is.
How PHP stores sessions
It uses a key-value store with long semi-random keys, one for each user. The key is called session ID ...