Jump to content


Photo

start_session() displaying error reports even if put at the first line


  • Please log in to reply
1 reply to this topic

#1 kubak

kubak
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 30 September 2006 - 07:29 PM

Hey guys,

I have a problem with sessions (I guess) :)

I get this warning:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at c:\Program Files\Apache\htdocs\amtest-tm\index.php:1) in c:\Program Files\Apache\htdocs\amtest-tm\index.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at c:\Program Files\Apache\htdocs\amtest-tm\index.php:1) in c:\Program Files\Apache\htdocs\amtest-tm\index.php on line 3

I get this warning everytime I run the index.php script. It's pretty weird since it looks like this:

<?php
ob_start();
session_start();

.
.
.

<?php
  ob_end_flush();
?>



There are NO whitespaces, empty lines or any other stuff that could cause php to display this error.. I tried to find solution on google but found nothing so far.. Any ideas?

Thanks, Jakub.

#2 kubak

kubak
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 30 September 2006 - 08:07 PM

I've found the solution!

I read through php.net functions list forums and found following comment:

devonmitton at gmail dot com
26-Jul-2006 10:35
I ran into the problem of losing the session after i redirect the user with header( location:);

I found that the problem doesn't occur in php5. Atleast for myself. I tested it on IIS as well as Apache and both times using php5 fixed the issue.

Secondly, I found a weird solution: The website i'm building required Cyrillic type, so i encode the pages using UTF-8. The problem that happens is that UTF-8 sends information before the php tags, and therefore before the session_start(); which ultimately renders the session_start(); call ineffective.

The UTF-8 encoding sends a small chunk of information before anything. This is called BOM (byte order marks).

To ensure that they don't show up, you need to save your files with a UTF-8 encoding which bypasses BOM. BBEdit for the Macintosh with allow for this under the file encoding options.

To recap: In this instance and for my situation, UTF-8, no BOM will allow sessions to pass through the header( location:); redirect, or using PHP5.

Hope this helps someone! [i will also repeat this comment under the header() function]


The reason is that I used to save the script with BOM which actually caused the session not to work properly. Hope this helps someone else as well :)

Jakub.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users