#native_company# #native_desc#
#native_cta#

Validating PHP User Sessions

By PHP Builder Staff
on April 4, 2008

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.
Let??s say that a user comes to your site and goes to page foo.php. On foo.php there is the ability to customize the page so that it only displays the information that the user wants to see, which we??ll assume is done via some handy JavaScript/DHTML. The user follows the instructions and modifies the page to match what s/he wants to view every day. The next day the user comes back to find that all the work that s/he did was in vain, because the page was unable to maintain the choices after the user left the page.
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.

1
|
2
|
3
|
4
|
5