MacFly 0 Report post Posted November 11, 2004 Hello I have a question regarding the header(location:http:// etc) function. I have a php document that looks similar to the followiing <? include("./top.php"); //this file contains loads of html and is resident on all pages in the site IT HAS TO BE HERE //now some code specific to this page only if blah blah { do some stuff } else { header("location : URL"; } include ("./bottom.php"); //this file contains loads of html and is resident on all pages in the site IT HAS TO BE HERE ----- my question is this, how can i redirect to a new page using the header() function in the middle of a file like this ie when i have already passed a load of html and other stuff to the browser. When I run the above i get the following error Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/include/top-left.inc.php:129) in /var/www/html/comments.php on line 19 I am reasonably new to PHP and after investigation found out that to use the header() redirect there can not be any html or white space sent to the browser before the actual header() command Im sure there is a really simple solution to this but im a bit stumped and would appreciate some help. Share this post Link to post Share on other sites
BoSZ 0 Report post Posted November 11, 2004 what about exchanging header with include Share this post Link to post Share on other sites
greenmask 0 Report post Posted November 11, 2004 The only way I can think of doing this is adding the code into an if statement. Share this post Link to post Share on other sites
Spectre 0 Report post Posted November 17, 2004 Because the header() function sends raw headers, it has to be called before any other data is sent to the client - eg. via the echo() or printf() functions. My guess is that the script top.php (which is being called first) is sending some kind of output - you will have to cancel this if you want to send headers. greenmask's example should work fine. Share this post Link to post Share on other sites