kubak Posted September 30, 2006 Share Posted September 30, 2006 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 3Warning: 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 3I get this warning everytime I run the index.php script. It's pretty weird since it looks like this:[code]<?phpob_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. Quote Link to comment Share on other sites More sharing options...
kubak Posted September 30, 2006 Author Share Posted September 30, 2006 I've found the solution!I read through php.net functions list forums and found following comment:[tt]devonmitton at gmail dot com26-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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.