<

Simple PHP Session Tutorial

Published on
8,355 Points
5,155 Views
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'
<?php
  session_start();
?>

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.
2
Comment
0 Comments

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Join & Write a Comment

The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Other articles by this author

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month