headers already sent - works in local but not on the host!?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ijekic
Forum Newbie
Posts: 11
Joined: Sat Aug 16, 2008 11:36 am
Location: Belgrade, Serbia

headers already sent - works in local but not on the host!?

Post by Ijekic »

I tried redirecting a page with header() and all I got was that dreadful "header already sent by".
I tried using ob_start() and similar... but with no luck.

Then I just created one php file:

Code: Select all

<?php header ('location: http://somelocation.com'); ?>
I tried that file at my localhost apache server and it worked and redirected, but when I uploaded it to my webhost server - the warning message appeared again! :banghead:

What on earth was already sent, when the ONLY command was the header itself??
Then I erased the line above and added this code only

Code: Select all

var_dump(headers_list());
Surprisingly, that command produced strange results:

when used on my localhost:
array(1) { [0]=> string(23) "X-Powered-By: PHP/5.2.6" }

but on webhost:
array(2) { [0]=> string(23) "X-Powered-By: PHP/5.2.6" [1]=> string(23) "Content-type: text/html" }

Why and who added the "content-type"!? What's going on?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: headers already sent - works in local but not on the host!?

Post by VladSun »

Found in php.ini:

Code: Select all

; As of 4.0b4, PHP always outputs a character encoding by default in
; the Content-type: header.  To disable sending of the charset, simply
; set it to be empty.
;
; PHP's built-in default is text/html
default_mimetype = "text/html"
default_charset = "utf-8"
 
 
There are 10 types of people in this world, those who understand binary and those who don't
Ijekic
Forum Newbie
Posts: 11
Joined: Sat Aug 16, 2008 11:36 am
Location: Belgrade, Serbia

Re: headers already sent - works in local but not on the host!?

Post by Ijekic »

I too have the same values (default text/html) in php.in, but it works on my machine... and I don't get the same output. :?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: headers already sent - works in local but not on the host!?

Post by VladSun »

Maybe this one then: http://www.askapache.com/htaccess/setti ... ccess.html

Edit: No ... couldn't be that one
There are 10 types of people in this world, those who understand binary and those who don't
Ijekic
Forum Newbie
Posts: 11
Joined: Sat Aug 16, 2008 11:36 am
Location: Belgrade, Serbia

Re: headers already sent - works in local but not on the host!?

Post by Ijekic »

... geeeez.... the problem was the in EDITOR (I'm using InType)!
I accidentally put UTF-8 instead of UTF-8 Plain and THAT caused this mess!!! I cannot believe it. :banghead:

Fortunately, the problem is solved!
So do NOT mess with the encoding in the editor or you'll face headers already sent by.
Post Reply