Computers

Overcome PHP session errors

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.sessionstart]: 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 !

Share this post

Related Posts

5 thoughts on “Overcome PHP session errors”

  1. mee41 says:

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

  2. Maldives Atoll says:

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

  3. Pingback: People Q&A !
  4. rakesh rai says:

    your post really worked for me
    thank you

  5. rakesh rai says:

    your post helped me
    thanks..

Comments are closed.