PHP Session & Session Variables
Posted by tutor | Posted in PHP Tutorial | Posted on 15-12-2009-05-2008
0
A PHP session allows you to store user information like username, shopping cart items, etc or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.
However, this session information is temporary and is deleted very quickly after the user has left the website that uses sessions.
It is important to think and verify if the sessions’ temporary storage is applicable to your website. If you require a more permanent storage you will have to use a database.
Sessions too have some major loop holes which need some advanced techniques to fill into those gaps. So if you are not experienced with session programming it is not recommended that you use sessions on a website that requires high-security.
PHP Session Variables
Session is the duration for which you browse a website or you visit some page. That means, when you are working with an application, you open it, do some changes and then you close it. This is a Session. The time you login to an application or start it the computer recognizes you.
It knows when you start the application and when you end. This is the case with applications running on your system, but on the internet there is one problem: HTTP address doesn’t maintain state, so a web server cannot know who you are and what you do.
A PHP session is used to solve this problem. It allows you to store user information on the server for later use. However, session information is temporary and is deleted after the user has left the website. If you need a permanent storage you may want to store the data in a database.
Sessions work by creating a unique id (UID) for each visitor and store variables based on this UID. The UID is either stored in a cookie or is propagated in the URL.
