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 <eeQuote>Cannot send session cache limiter - headers already sent</eeQuote>
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;
1: 2: 3: 4: 5:
'Add a space here or any character' <?php session_start(); ?>
- 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 <?php code body. Anything put before the opening <?php line that can be printed to a webpage, including a simple space, will cause this error.
Fixing this problem is just as simple as the problem itself. Simply remove the entire line before the opening <?php block and resave your file. Upload the newly saved file and pull it up in your browser again. (NOTE: Sometimes a hard refresh may be needed...this is achieved by holding down your shift key while clicking the refresh button on your browser.)
And voila! Problem solved!
This was a test article submission and was meant to aid in the beta testing of this new feature.