Jump to content

[SOLVED] headers already sent by ... (I have read the FAQ, etc.)


tobylechien

Recommended Posts

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 ?

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="

 

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

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.

Archived

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

×
×
  • 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.