tutebox.com

Computers

Overcome PHP session errors

July 10, 2010 by Sudantha Gunawardena in PHP with 5 Comments

I think that most of the php beginners will facing a common problem on PHP session getting a warning message like this when using sessions.

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent……

For this warning there are many reasons and few fixes that can be overcome this problem.

Why this occur?

1.HTML Tags before the Session_start();

Always the PHP session should be initialized before any other output in your PHP page. Especially HTML tags when you are using a HTML editor like Microsoft expression web HTML tags can be automatically generated because the session initialization.

2. White spaces and unwanted characters

Some this before the or after the PHP tags there may be unwanted spaces or characters generated.

3. echo before session_start();

Print any output before the session initiation will generate this warning

How to avoid!

Simply make sure that above things doesn’t happen.!!

  1. Make sure not to put any HTML tags before and your first line in the PHP should be <?php session_start(); ?> !
  1. Any white spaces before or after <?php ?> tags should be avoided
  1. Any echo ”output”; prints should be avoided before the <?php session_start(); ?>
  1. Also try not using the closing PHP tag (?>)

Still got the error? Have a FIX!

If you still got the error a small trick that you can do is there! If you can’t fix it avoid it, as this is a warning message this is not affect the run time! So you can just ignore the error message like this:

<?php @session_start(); ?>

Put a @ before the session_start(); so this will ignore the error message !

Tagged

Recommend this post

Related Posts

5 Comments

  1. mee41July 11, 2010 at 12:58 pmReply

    i had so much doubts in this.. thanks….

  2. Maldives AtollJuly 12, 2010 at 9:03 pmReply

    Fabulous blog post, plenty of superb info. I want to show my friend and ask them the things they think.

  3. People Q&A !July 13, 2010 at 7:56 amReply

    I found your entry interesting thus I’ve added a Trackback to it on my weblog :)

  4. rakesh raiSeptember 21, 2011 at 6:35 pmReply

    your post really worked for me
    thank you

  5. rakesh raiSeptember 21, 2011 at 6:38 pmReply

    your post helped me
    thanks..

Leave a reply

Your email address will not be published. Required fields are marked *

*

Stay Connected