Be the first to write a review
Working with Session Variables in PHP
In this tutorial, we look at using Session Variables in PHP, to store user information as a user moves backwards and forwards through the pages of a website. This allows information to be tied to a user, linking them to records in a database to create a shopping cart (for example). Session Variables are also commonly used for security systems, so that once a user has logged in their status is held in a Session Variable.
The first section that we examine is how Session Variables work, and how to enable them in PHP if they're not already enabled. We then look at how to store a value in a Session Variable, and how to avoid the common "Headers already sent" error that can occur, and how it can be stopped permanently by using Output Buffering.
We then look at how to read back a Session Variable and how to check whether a Session has been set or not. Finally, we look at when to use Session Variables and when to use Cookies, and how to destroy a Session Variable.
Gareth Downes-Powell
Gareth has a range of skills, covering many computer and internet related subjects. He is proficient in many different languages including ASP and PHP, and is responsible for the setup and maintenance of both Windows and Linux servers on a daily basis.
In his daily web development work he uses the complete range of Macromedia software, including Dreamweaver MX, Flash MX, Fireworks MX and Director to build a number of websites and applications. Gareth has a close relationship with Macromedia, and as a member of Team Macromedia Dreamweaver, he has worked closely in the development of Dreamweaver, and was a beta tester for Dreamweaver MX.
On a daily basis he provides support for users in the Macromedia forums, answering questions and providing help on a range of different web related subjects. He has also written a number of free and commercial extensions for Dreamweaver MX, to further extend its capabilities using its native JavaScript API’s or C++.
As a web host, Gareth has worked with a range of different servers and operating systems, with the Linux OS as his personal favourite. Most of his development work is done using a combination of Linux, Apache and MySQL and he has written extensively about setting up this type of system, and also running Apache and MySQL under Windows.