PDA

View Full Version : Headers already sent...


mr e
08-04-2002, 07:51 PM
Ok this is what I get...

Warning: Cannot add header information - headers already sent by (output started at /usr/local/psa/home/vhosts/wcgalaxy.com/httpdocs/index.php:26) in /usr/local/psa/home/vhosts/wcgalaxy.com/httpdocs/shoutbox.php on line 31


Here is line 26 of index.php

<? include ("header.php") ?>


and here is line 31 of shoutbox.php

header ("Location: http://www.wcgalaxy.com/");


I can't for the life of me, figure out how to get it to not give me this error when you hit submit on the shoutbox, when you hit submit, it basically writes to a text file and then tries to refresh the page to display your shout, but when it refreshes I get this error.

Xenon
08-04-2002, 08:19 PM
be sure you don't have any output before the header() function in your shoutbox.php

mr e
08-04-2002, 08:45 PM
what i have is

if (this) {
print "something"
} else {
variable declaration and such
header()


would the print have anything to do with it?

Xenon
08-04-2002, 08:48 PM
yes that's it...

you cannot use header after you have used print or echo or something like that

mr e
08-04-2002, 08:58 PM
ok i switched it around to do

if (this) {
variable declaration and such
header()
} else {
print "something"
}

but it's still giving me the same error

Xenon
08-04-2002, 09:05 PM
be sure there are no other output functions before the header:

remeber a empty line after the last ?> in header.php or a empty line before the first <? are also outputs

mr e
08-04-2002, 09:11 PM
well header.php is all HTML, and it looks like it's not even running the header() command so is there any other way to redirect you to a page after you hit Submit? I have...

if ($submit) {
variables and stuff
header()
} else {
HTML form
}

and i want to redirect the user after he/she hits submit

Xenon
08-04-2002, 09:16 PM
you could code a redirect with javascript (look at how vb makes that)

don't ask me how to code javascript, i don't know javascript ;)

mr e
08-04-2002, 09:23 PM
wow, i just figured that out then read your post, for javascript you do...

<script language="javascript">
window.location.href=("<?php echo $url; ?>");
</script>


thanks for the help though :D