tobylechien Posted October 20, 2007 Share Posted October 20, 2007 I kept getting this error after having inserted a session_start() in my script: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at ....) in so I did some research, read manuals, FAQs, forums, etc. I changed my script in order to have session_start at the very top of my script. I kept getting the same error eventhough I don't see what can be sent before session_start : there is nothing (not even a single space). So I tried this simple new page for testing purposes: <?php session_start(); ?> <html> <body> test </body> </html> And I still get the error. In fact, I get it twice: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\projets\test.php:1) in C:\projets\test.php on line 1 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\projets\test.php:1) in C:\projets\test.php on line 1 test Could this come from the apache config, adding automatically something ? I tried the script on various servers (home XP machine, hosting account under linux, etc.) I am missing something here ? Quote Link to comment https://forums.phpfreaks.com/topic/74122-solved-headers-already-sent-by-i-have-read-the-faq-etc/ Share on other sites More sharing options...
darkfreaks Posted October 20, 2007 Share Posted October 20, 2007 ob_start(); put that before session_start() Quote Link to comment https://forums.phpfreaks.com/topic/74122-solved-headers-already-sent-by-i-have-read-the-faq-etc/#findComment-374288 Share on other sites More sharing options...
tobylechien Posted October 20, 2007 Author Share Posted October 20, 2007 ob_start(); put that before session_start() I tried that. Same result. Quote Link to comment https://forums.phpfreaks.com/topic/74122-solved-headers-already-sent-by-i-have-read-the-faq-etc/#findComment-374303 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 1. What editor are you using. 2. Are there any spaces between the page start and <?php 3. Are there anythings above that. 4. What are the "session" related settings in your ini file. Quote Link to comment https://forums.phpfreaks.com/topic/74122-solved-headers-already-sent-by-i-have-read-the-faq-etc/#findComment-374304 Share on other sites More sharing options...
tobylechien Posted October 20, 2007 Author Share Posted October 20, 2007 1. I am using Notepad++ 3.6 2. No space between <?php and very begining of file. The character < is at ln 1 col 1 3. nope. 4. in php.ini, see below (I removed the comments). output_buffering = On [session] session.save_handler = files session.save_path = "C:\xampp\tmp" session.use_cookies = 1 session.name = PHPSESSID session.auto_start = 0 session.cookie_lifetime = 0 session.cookie_path = / session.cookie_domain = session.serialize_handler = php session.gc_probability = 1 session.gc_divisor = 100 session.gc_maxlifetime = 1440 session.bug_compat_42 = 1 session.bug_compat_warn = 1 session.referer_check = session.entropy_length = 0 session.entropy_file = session.cache_limiter = nocache session.cache_expire = 180 session.use_trans_sid = 0 session.hash_function = 0 session.hash_bits_per_character = 4 url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset=" Quote Link to comment https://forums.phpfreaks.com/topic/74122-solved-headers-already-sent-by-i-have-read-the-faq-etc/#findComment-374309 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 <?php session_start(); ?> <html> <head> </head> <body> <?php $_SESSION['test'] = 'hello'; echo $_SESSION['test']; ?> </body> </html> Try that and tell me what happens. Quote Link to comment https://forums.phpfreaks.com/topic/74122-solved-headers-already-sent-by-i-have-read-the-faq-etc/#findComment-374312 Share on other sites More sharing options...
thebadbad Posted October 20, 2007 Share Posted October 20, 2007 If you are saving your file in UTF-8 encoding, it could be the BOM (Byte Order Mark). Quote Link to comment https://forums.phpfreaks.com/topic/74122-solved-headers-already-sent-by-i-have-read-the-faq-etc/#findComment-374313 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 Never heard of that, please explain? Quote Link to comment https://forums.phpfreaks.com/topic/74122-solved-headers-already-sent-by-i-have-read-the-faq-etc/#findComment-374317 Share on other sites More sharing options...
tobylechien Posted October 20, 2007 Author Share Posted October 20, 2007 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\projets\test2.php:1) in C:\projets\test2.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\projets\test2.php:1) in C:\projets\test2.php on line 2 hello Quote Link to comment https://forums.phpfreaks.com/topic/74122-solved-headers-already-sent-by-i-have-read-the-faq-etc/#findComment-374321 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 Something strange. He might be right as he mentioned above, never encountered that. Paste a link to the test page. Quote Link to comment https://forums.phpfreaks.com/topic/74122-solved-headers-already-sent-by-i-have-read-the-faq-etc/#findComment-374324 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 Based on what he said what encoding are you saving your file in? Quote Link to comment https://forums.phpfreaks.com/topic/74122-solved-headers-already-sent-by-i-have-read-the-faq-etc/#findComment-374327 Share on other sites More sharing options...
tobylechien Posted October 20, 2007 Author Share Posted October 20, 2007 Based on what he said what encoding are you saving your file in? Notepad ++ says UTF-8. Here is a link : http://www.coteaudenogent.fr/test2.php (not on the same serveur though, but same error). Quote Link to comment https://forums.phpfreaks.com/topic/74122-solved-headers-already-sent-by-i-have-read-the-faq-etc/#findComment-374329 Share on other sites More sharing options...
thebadbad Posted October 20, 2007 Share Posted October 20, 2007 The BOM is a character at the very start of the document used to identify the document's encoding as UTF-8/16/32. It's not needed however, so I never include it in my documents (in Notepad++ you can choose the format "UTF-8 without BOM"), because of all the problems it could and will make eventually Use a HEX editor to see the BOM, and remove it that way if you don't use Notepad++. To tobylechein: Maybe you can solve this by choosing "UTF-8 without BOM". It's at least possible in version 4.1.2 I'm using. Quote Link to comment https://forums.phpfreaks.com/topic/74122-solved-headers-already-sent-by-i-have-read-the-faq-etc/#findComment-374331 Share on other sites More sharing options...
tobylechien Posted October 20, 2007 Author Share Posted October 20, 2007 Ok, just tried in ANSI. Problem solved. I will use UTF-8 without BOM as suggested. You guys are really really good. Thank you so much. :) Quote Link to comment https://forums.phpfreaks.com/topic/74122-solved-headers-already-sent-by-i-have-read-the-faq-etc/#findComment-374332 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 Well it's marked as solved, we can assume the issue has been fixed. Quote Link to comment https://forums.phpfreaks.com/topic/74122-solved-headers-already-sent-by-i-have-read-the-faq-etc/#findComment-374334 Share on other sites More sharing options...
thebadbad Posted October 20, 2007 Share Posted October 20, 2007 Thank you so much. :) You're welcome Quote Link to comment https://forums.phpfreaks.com/topic/74122-solved-headers-already-sent-by-i-have-read-the-faq-etc/#findComment-374339 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.