|
|
|
|
![]() ![]() |
Nov 11 2004, 12:24 PM
Post
#1
|
|
|
Newbie [Level 2] ![]() ![]() Group: Members Posts: 36 Joined: 9-November 04 Member No.: 2,202 |
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 : http://some_page.php"); } 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. |
|
|
|
Nov 11 2004, 12:32 PM
Post
#2
|
|
|
the one with a short temper ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 247 Joined: 26-July 04 Member No.: 211 |
what about exchanging
header with include |
|
|
|
Nov 11 2004, 10:29 PM
Post
#3
|
|
|
Newbie [Level 1] ![]() Group: Members Posts: 11 Joined: 11-November 04 Member No.: 2,236 |
The only way I can think of doing this is adding the code into an if statement.
<?php if ($something = something) { include("top.php"); // page specific code here include("bottom.php"); } else { header("Location: http://whatever.com"); } ?> -gm |
|
|
|
Nov 17 2004, 06:24 AM
Post
#4
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 874 Joined: 30-July 04 Member No.: 246 |
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. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 8th October 2008 - 03:50 AM |