You are here: Re: PHP headers not working :( « All PHP « IT news, forums, messages
Re: PHP headers not working :(

Posted by J.O. Aho on 08/16/06 19:36

Sonia Covarrubias wrote:
> Hello :) I am new to PHP and am having one particular problem which has been
> repeatedly causing me trouble..
>
> I've manually installed on my winXP machine apache2 and php4. For some
> reason all my headers give me the error "WARNING, headers already sent
> by..." common error it seems.. so, I cannot run headers, cookies, sessions..
> etc..
>
> I've been reading and searching, and i've come up with 2 solutions..
> 1. there are extra carriage returns somewhere which are causing this.
> 2. change output_buffering to "On" in PHP.ini.
>
> using #2 worked.. but it according to many it is the wrong solution...
> Well.. i've gone through the session files i'm experimenting with.. no extra
> spaces anywhere..

You aren't allowed to make any output at all, this includes the include files
you include, then main file.

--- example file ---
<html><head>
<?php
header("Location: http://www.example.com/");
?>
</head><body></body></html>
--- end of file ---

This small example file don't have any line feeds or white spaces, but still
not valid to be used with header() as the html tags are output and therefore
prevents the header to be sent as it comes after output.


--- example file2 ---
<?php
include "include1.php";
header("Location: http://www.example.com/");
?>
--- end of file ---

--- include1.php ---
<?php
$variable="Hello";
?>

--- end of file ---

This two file setup will also generate an error message as the include file
has a new line in the end.

> Any ideas?

You need to clean your code and see to that NO output of any kind is done
before the usage of header(), no matter if it's whitespace, new line,
html-tags or data echo:ed out.


> and i've looked through PHP.ini line by line.. deleted
> every single extra space using Windows Notepad.. and still, the same headers
> error when output_buffering is at it's default "Off"...

php.ini isn't affecting things, it's the config file, it's only those files
that you written yourself ending with .php that you should remove all
whitespaces, newlines, html-tags and echo's before the usage of header(),
remember that include files can't hold any output data outside the <?PHP ?>.


//Aho

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация