Jump to content

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


kubak

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.
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.