Jump to content

Archived

This topic is now archived and is closed to further replies.

kubak

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

Recommended Posts

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:

[code]<?php
ob_start();
session_start();

.
.
.

<?php
  ob_end_flush();
?>[/code]



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.

Share this post


Link to post
Share on other sites
I've found the solution!

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

[tt]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][/tt]

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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.