Validating PHP User Sessions
What are Sessions for?
Before we start digging into how to manage user sessions, it is important to first understand what sessions are for. In a nutshell, sessions are the way that we ??maintain state?? from one page to the next, that is, how we identify specific users across multiple page requests. The ability to track users as they go from one page to the next using sessions allows us a number of options, such as tracking where they are going (web statistics) or to verify credentials for a specific section of the site.
Clearly the above example would frustrate most users and they would not want to keep coming back to your site. So, in order to allow the user to make changes that will be maintained, we have to have a way to store the user??s choices (most likely a database), and a way to identify unique users so that we can tell the difference between user A and user B when both are logged in simultaneously, which is where Sessions come into play. When the user comes to the site, we need to be able to give them a unique identifier (a session id) that will allow us to know the difference between each user on the site. So, when the user logs in, and then modifies their choices for foo.php, we know whose profile to save those changes to.