Header

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
taboas
Forum Newbie
Posts: 4
Joined: Tue Mar 18, 2003 1:50 pm

Header

Post by taboas »

The following error appears

Warning: Cannot modify header information - headers already sent by (output started

The instruction is:

mysql_close($conexion);
$vuelta = "inicio.php";
header("Location: ". $vuelta);
exit;
bionicdonkey
Forum Contributor
Posts: 132
Joined: Fri Jan 31, 2003 2:28 am
Location: Sydney, Australia
Contact:

Post by bionicdonkey »

header can only be send before any output has been sent to the browser...i think
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

BD: you are correct. The header() function only works before any output is sent.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

sleepingdanny
Forum Newbie
Posts: 12
Joined: Thu Mar 20, 2003 4:27 am
Location: Israel

Post by sleepingdanny »

More easy explantion: :)
"header()" is need to be placed above the <html> tag or it will show the error...

1) mysql_close($conexion);
2) $vuelta = "inicio.php";
3) header("Location: ". $vuelta);
4) exit;
<html>
<head>
.....

The 3rd line is wrong - it should be :arrow:
header("Location: . $vuelta"); and not header("Location: ". $vuelta);
Last edited by sleepingdanny on Thu Mar 20, 2003 4:55 am, edited 2 times in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

sleepingdanny wrote:More easy explantion: :)
"header()" is need to be placed above the <html> tag or it will show the error...
That's a simple explanation but you can still get the error if you have whitespace above the <html> tag or if you echo() something above the <html> tag so it's not the whole answer :wink: .

Mac
sleepingdanny
Forum Newbie
Posts: 12
Joined: Thu Mar 20, 2003 4:27 am
Location: Israel

Post by sleepingdanny »

I don't know if this is true because it never happend to me :?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

sleepingdanny wrote:I don't know if this is true because it never happend to me :?
It is true - you cannot output anything (and whitespace counts as something) to the browser before calling the header() function. That is of course unless you use output buffering:
http://www.php.net/manual/en/ref.outcontrol.php

This is because PHP doesn't know HTML so it doesn't check to see if the function is being called before the <html> tag, it checks to see if the function is being called before there is any output to the browser.

Mac
Post Reply