CPP_code Posted March 29, 2010 Share Posted March 29, 2010 Hello all, I get the following error when executing the following code. Does anyone have any ideas: Warning: Cannot modify header information - headers already sent by (output started at /home/cprath7074k/PHP/do_redirect.php:2) in /home/cprath7074k/PHP/do_redirect.php on line 3 "index.html file" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> Redirection Menu </TITLE> </HEAD> <BODY> <FORM method="POST" action="do_redirect.php"> <br>I want to go to: <SELECT name="url" size="1"> <OPTION value="http://www.cnn.com/">CNN</OPTION> <OPTION value="http://espn.cnn.com/">ESPN</OPTION> <OPTION value="http://www.9news.com/">9News</OPTION> <OPTION value="http://www.denverpost.com/">Denver Post</OPTION> </SELECT> <INPUT type="submit" value="Go!"> </FORM> </BODY> </HTML> "do_redirect.php file" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <?php header("location:$_POST"); ?> <HTML> <BODY> </BODY> </HTML> Link to comment https://forums.phpfreaks.com/topic/196881-header-code-use-problem/ Share on other sites More sharing options...
zeodragonzord Posted March 29, 2010 Share Posted March 29, 2010 header() only works if nothing else is printed on the page first. Therefore, it needs to be placed before any of the HTML. Link to comment https://forums.phpfreaks.com/topic/196881-header-code-use-problem/#findComment-1033628 Share on other sites More sharing options...
CPP_code Posted March 29, 2010 Author Share Posted March 29, 2010 What am I printing in HTML before calling the header() function? The only line I see is the doc type...but that's a comment. Link to comment https://forums.phpfreaks.com/topic/196881-header-code-use-problem/#findComment-1033631 Share on other sites More sharing options...
zeodragonzord Posted March 29, 2010 Share Posted March 29, 2010 That counts too. It needs to go before anything gets rendered. Try putting <?php header(); ?> in the first line before DOCTYPE and any HTML and see if it works. Link to comment https://forums.phpfreaks.com/topic/196881-header-code-use-problem/#findComment-1033636 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2010 Share Posted March 29, 2010 The doctype is HTML. It is in fact the daddy html tag that tells what kind of html the page contains. It's also not a comment <!-- --> and if it was, that is a HTML comment, which is html, which is something that is output to the browser. Link to comment https://forums.phpfreaks.com/topic/196881-header-code-use-problem/#findComment-1033639 Share on other sites More sharing options...
CPP_code Posted March 29, 2010 Author Share Posted March 29, 2010 This code fixed the problem. <?php header("location:$_REQUEST"); exit; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <BODY> </BODY> </HTML> I sweat I thought I tried that before...a couple of times even. Maybe frustration made be believe I tried it a couple of times. I really appreciate your help guys/gals. Have a great day. Link to comment https://forums.phpfreaks.com/topic/196881-header-code-use-problem/#findComment-1033652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.