Jump to content

This problem refuses to go

- - - - -

  • Please log in to reply
9 replies to this topic

#1
tayolad

tayolad

    Newbie

  • Members
  • PipPip
  • 27 posts
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.

#2
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
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:

<?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
grisha

grisha

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
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
tayolad

tayolad

    Newbie

  • Members
  • PipPip
  • 27 posts
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
tayolad

tayolad

    Newbie

  • Members
  • PipPip
  • 27 posts
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.

#6
grisha

grisha

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
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
xsonline

xsonline

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
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 :).

#8
tayolad

tayolad

    Newbie

  • Members
  • PipPip
  • 27 posts
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.

#9
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
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.

#10
tayolad

tayolad

    Newbie

  • Members
  • PipPip
  • 27 posts
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