Translate

Saturday, August 24, 2013

Warning: session_start() [function.session-start]: Cannot send session cache limiter or cookie

PHP WARNING:

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


Explanation:
This problem is normally cause because an html code was placed above the header. You need to be careful on that. header must be parse BEFORE html code.  

Definiton: 

The header() function sends a raw HTTP header to a client. 
It is important to notice that header() must be called before any actual output is sent (In PHP 4 and later, you can use output buffering to solve this problem): for more... w3schools.com

<html>
<?php
// This results in an error.
// The output above is before the header() call
header('Location: http://www.example.com/');
?>

Solution1:
ALWAYS MAKE SURE THAT session_start() is in the first line.

1  <?php
2  session_start();
3  ..................
4  ..................
5  ..................
6  ?>

Solution2:
You can place this line into  your code.

// place this at the top of your page : ob_start()  stored the output in the buffer
<? ob_start(); ?>
// place this at bottom of you page :  ob_flush() flush the buffer
 <?ob_flush();?>



Thank You, Hope this was helpful

No comments:

Post a Comment