[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More


Simple PHP Session Tutorial

Published on
8,432 Points
2 Endorsements
Last Modified:
Sessions can be extremely useful when developing content that requires the ability to be able to carry over from page to page without the use of posting form data. An application that commonly makes use of PHP sessions are authentication and registration systems.

Here, in this tutorial, I will attempt to layout the basics of a simple session with examples and descriptions that will support the examples.

Probably the greatest stumbling block that will almost invariably get in the way of every new PHP developer is the issue of creating a new session, but with the error Cannot send session cache limiter - headers already sent

This error is almost always due to one very simple mistake and it's solution is just as simple to resolve. So, let's start by showing the code snippet that will cause this error followed by it's simple solution so that you can get rolling in creating working and useful sessions in PHP.

1. Create a test.php file

Using your favorite editor, create a file called test.php and save it to a local development directory (or folder for you windows users)

2. Add PHP code

Now you are going to want to add the following code to this file;

'Add a space here or any character'

Open in new window

3. Save & Upload your work

Now it's just a matter of saving your file and uploading it to your webserver. I'll assume that you have a good understanding of that side of things.Once you have completed the above mentioned steps, now go ahead and call up test.php from your webserver in your browser and you should see an error report like the one mentioned above.

As you can see from the code snippet. There is a line of non-PHP page content above the opening

Fixing this problem is just as simple as the problem itself. Simply remove the entire line before the opening

And voila! Problem solved!

This was a test article submission and was meant to aid in the beta testing of this new feature.

Featured Post

Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Join & Write a Comment

Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Other articles by this author

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month