tags:

views:

410

answers:

3

This are my first two lines:

<?php
header('Content-Type: application/x-javascript');

And it gives me the headers already sent in line 1.

It is intended to generate a JavaScript file that loads from an HTML page, when checked the JavaScript file from Firebug i got the following file:

1  <br />
2  <b>Warning</b>: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\totoro\Js\libs.php:1) in <b>C:\Program Files\Apache Group\Apache2\htdocs\totoro\Js\libs.php</b> on line <b>1</b><br />
3  var Totoro = {}, $t = Totoro;

As you can see, it spits a character that looks like garbage characters, but nothing is sended, the first line is a header function call. What might be the problem?

+6  A: 

This character sequence is the UTF-8 BOM. When using UTF-8, save your files without BOM (sometimes also called signature).

Additionally you should declare the encoding you’re using. Because as the UTF-8 BOM is shown as the characters you named, your data is probably interpreted with ISO 8859-1, as the UTF-8 BOM byte sequence 0xEFBBBF represents the characters ï (0xEF), » (0xBB) and ¿ (0xBF) in ISO 8859-1.

So remove the BOM and use this Content-Type header field along with the correct MIME type application/javascript and charset parameter:

Content-Type: application/javascript;charset=utf-8
Gumbo
+10  A: 

You have most probably saved the file as UTF-8 with BOM (Byte-order mark), resave it as UTF-8 without said thingy.

olle
A: 

I foudn this on wikipedia: http://en.wikipedia.org/wiki/Byte-order_mark#Representations_of_byte_order_marks_by_encoding

This made me change the preferences of my Komodo editor an there is a "Encoding: use signature (BOM)" checked. Once unchecked the problem is solved.

gansodesoya