SOS.
I use session_start() at the begining of a page but receive this error message. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent...
Please help to remove this.
9 replies to this topic
#1
Posted 08 February 2011 - 10:46 PM
|
|
|
#2
Posted 08 February 2011 - 11:05 PM
Headers already sent. You can't send things like cookies after sending ANYTHING to the browser. By anything, I mean anything including html and whitespace. Even the smallest space before your opening php tag can cause that error.
A common mistake is including a file with whitespace. Example:
A common mistake is including a file with whitespace. Example:
<?PHP
// index.php
// Has NO whitespace on this page
include('file.php');
session_start();
<?PHP
//file.php
function doStuff(){
// do stuff
}
?>
In file.php and index.php there is no whitespace before the opening php tag, but in "file.php" at the end, I close PHP and it has a space at the end which gets included before the session has started, which is sent to the browser. It's good practice not to close PHP Tags in files that don't output to the browser.
#3
Posted 08 February 2011 - 11:34 PM
Can you paste the full error message? I believe there's information about the file causing the problem. General rule:
<?php session_start(); /* everything else goes here */ ?>
#4
Posted 08 February 2011 - 11:54 PM
Thank you. I checked, but there seems to be no blank space anywhere. I have checked all the included files also and there are no blank spaces. I have been battling with this thing for some hours now. Please help.
#5
Posted 09 February 2011 - 12:02 AM
This is the error message: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/xyz/public_html/php_scripts/staffmainpage.php:1) in /home/xyz/public_html/php_scripts/staffmainpage.php on line 2
and this is the first few code of the file staffmainpage.php:<?php
session_start();
$messages=array();
require('../../funcs_and_includes/php_includes/primary_include.php');
require('../../funcs_and_includes/php_includes/fnValidators.php');
require('../../funcs_and_includes/php_includes/fnConnectToDB.php');
require('../../funcs_and_includes/php_includes/fnMyFunctions1.php');
$school_name="";$school_address="";I have checed all the included, no spaces.
and this is the first few code of the file staffmainpage.php:<?php
session_start();
$messages=array();
require('../../funcs_and_includes/php_includes/primary_include.php');
require('../../funcs_and_includes/php_includes/fnValidators.php');
require('../../funcs_and_includes/php_includes/fnConnectToDB.php');
require('../../funcs_and_includes/php_includes/fnMyFunctions1.php');
$school_name="";$school_address="";I have checed all the included, no spaces.
#6
Posted 09 February 2011 - 09:07 AM
If those files are encoded with UTF8 check the BOM settings. If the file is encoded with BOM convert it to UTF8 without BOM. Basically do it with all your files.
#7
Posted 09 February 2011 - 01:09 PM
Why not try replacing session_start(); by die();
This helps you to check if there realy is nothing sent before. I know it's a strange trick, but it usually works for me :).
This helps you to check if there realy is nothing sent before. I know it's a strange trick, but it usually works for me :).
#8
Posted 09 February 2011 - 10:07 PM
If the file is encoded with BOM convert it to UTF8 without BOM. Basically do it with all your files.
grisha, How do I do the conversion?. I discovered that the preceding script file is ascii.
grisha, How do I do the conversion?. I discovered that the preceding script file is ascii.
#9
Posted 10 February 2011 - 10:03 PM
If you are in Windows, try opening up your PHP page with notepad, and saving the document (File -> Save As) and ensure the drop down menu ANSI is selected. Then try testing that specific file, it should pass assuming you've no other visible whitespace. If it still persists, then we can look at other options.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#10
Posted 10 February 2011 - 11:32 PM
hey! I must thank everyone that contributes to this. The problem solved. Great! I followed alexandra's advise and it works. Thank you all.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top










