bsamson Posted January 16, 2008 Share Posted January 16, 2008 Getting the follow error: Warning: Cannot modify header information - headers already sent by (output started at /home/myusername/public_html/ext/add.php:1) in /home/myusername/public_html/ext/add.php on line 4 With this code: <? if ($_POST['acode'] !== "h7p3bf83" && $_GET['add'] !== "y") { header('Location: http://www.mydomain.com/ext/'); } else { // Do Nothing } ?> I am utterly confused! I understand what this error is, however I do not understand why this script is triggering this. This script processes the result of a HTML form. Anything stick out? Thanks in advance for any help! PS: In this example this error is loading without the "?add=" switch. This error is displaying on the first run. Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/ Share on other sites More sharing options...
TheFilmGod Posted January 16, 2008 Share Posted January 16, 2008 post ALL your code - and then we can help you out. Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441108 Share on other sites More sharing options...
drummer101 Posted January 16, 2008 Share Posted January 16, 2008 PHP processing, when in regards to sending headers, needs to be taken care of BEFORE any HTML *OR* whitespace. Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441110 Share on other sites More sharing options...
bsamson Posted January 16, 2008 Author Share Posted January 16, 2008 What I posted is all the code that's processed. That IF statement is at the top of the script before anything is displayed. The HTML Form Page is just a simple page w/ 2 fields and the submit button. The code posted is the beginning of the script. Just by looking @ that do you see any problems? Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441111 Share on other sites More sharing options...
bsamson Posted January 16, 2008 Author Share Posted January 16, 2008 I understand when/how HEADERS ... I use them all over my site ... that's why this has me so stumped. Thanks though! Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441112 Share on other sites More sharing options...
TheFilmGod Posted January 16, 2008 Share Posted January 16, 2008 the header ( location: is on line 4 as the error message says therefore you have an extra line "white space" that is creating this problem. Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441113 Share on other sites More sharing options...
The Little Guy Posted January 16, 2008 Share Posted January 16, 2008 <?php if ($_POST['acode'] !== "h7p3bf83" && $_GET['add'] !== "y") { header('Location: http://www.mydomain.com/ext/'); } else { // Do Nothing } ?> If these are the very first lines, then I see nothing wrong, but if there is more above it, then we will need to see it. Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441114 Share on other sites More sharing options...
bsamson Posted January 16, 2008 Author Share Posted January 16, 2008 I just removed the space ... the code was: <? if ($_POST['acode'] !== "h7p3bf83" || $_GET['add'] !== "y") { header('Location: http://www.nexgenstores.com/ext/'); } else { // Do Nothing } ?> With Error: Warning: Cannot modify header information - headers already sent by (output started at /home/myusername/public_html/ext/add.php:1) in /home/myusername/public_html/ext/add.php on line 4 NOW, with code: <? if ($_POST['acode'] !== "h7p3bf83" || $_GET['add'] !== "y") { header('Location: http://www.nexgenstores.com/ext/'); } else { // Do Nothing } ?> Get this error: Warning: Cannot modify header information - headers already sent by (output started at /home/nnyserve/public_html/ext/add.php:1) in /home/nnyserve/public_html/ext/add.php on line 3 Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441116 Share on other sites More sharing options...
drummer101 Posted January 16, 2008 Share Posted January 16, 2008 edit: nvm Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441122 Share on other sites More sharing options...
bsamson Posted January 16, 2008 Author Share Posted January 16, 2008 <?php if ($_POST['acode'] !== "h7p3bf83" && $_GET['add'] !== "y") { header('Location: http://www.mydomain.com/ext/'); } else { // Do Nothing } ?> If these are the very first lines, then I see nothing wrong, but if there is more above it, then we will need to see it. No honestly ... there is nothing before ... Here's all the php: <?php if ($_POST['acode'] !== "h7p3bf83" || $_GET['add'] !== "y") { header('Location: http://www.mydomain.com/ext/'); } else { // Do Nothing } // http://www.mydomain.com/ext/?acode=h7p3bf83 if ($_GET['add'] == "y") { include "doadd.php"; } if (empty($msg1)) { if ($_GET['add'] !== "y") { $num = $_POST[num]; switch ($num) { case "3060": $location="Brunswick"; break; case "1881": $location="Buffalo"; break; case "8885": $location="Burlington"; break; case "1781": $location="Colonie"; break; case "2378": $location="Concourse"; break; case "7003": $location="Coxsackie"; break; case "1033": $location="Eastfield"; break; case "2812": $location="Elmira"; break; case "7111": $location="Glens Falls"; break; case "0039": $location="Hampshire"; break; case "9600": $location="Holyoke"; break; case "0242": $location="Latham"; break; case "1030": $location="North Pearl"; break; case "6282": $location="Queensbury"; break; case "9900": $location="Rutland"; break; case "1223": $location="Vestal"; break; case "6611": $location="Watertown"; break; case "0100": $location="Western"; break; case "0921": $location="Wilton Mall"; break; case "1200": $location="Liverpool"; break; default: $location="NF"; } } if ($location !== "NF") { $msg = "<b><center>ADD $location to database? <a href='add.php?add=y&loc=$location'>YES</a> or <a href='index.php'>NO</a></b></center>"; } else { $msg = "<b><center>LOCATION NOT FOUND! <a href ='index.php' title='Try again'>Try Again?</b></center>"; } } ?> URL WHEN THIS ERROR OCCURS: http://www.mydomain.com/ext/add.php Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441124 Share on other sites More sharing options...
trq Posted January 16, 2008 Share Posted January 16, 2008 edit: nevermind Thats makes no difference as it is simply ignored. Its whitespace outside of the <?php ?> tags that can cause an issue. Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441128 Share on other sites More sharing options...
bsamson Posted January 16, 2008 Author Share Posted January 16, 2008 I have a screnshot attached [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441134 Share on other sites More sharing options...
PFMaBiSmAd Posted January 16, 2008 Share Posted January 16, 2008 When the header error refers to line 1 of a php file when there is an opening php tag <?php on line 1, either your file has some white space (a space, tab, newline...) before the <?php tag on line 1 or your file is saved in UTF-8 format and the BOM (byte order mark) at the start of the file is being output as content to the browser. Insure you file has nothing before the <?php tag on line 1 and make sure the file is saved in ANSI/ASCII mode. Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441139 Share on other sites More sharing options...
paul2463 Posted January 16, 2008 Share Posted January 16, 2008 just loaded all your code as a direct copy from this thread into my system and it does not throw any errors, it tries to take me to http://www.mydomain.com/ext/' . Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441148 Share on other sites More sharing options...
The Little Guy Posted January 16, 2008 Share Posted January 16, 2008 could it be because you are using a short hand <? instead of <?php ??? Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441151 Share on other sites More sharing options...
bsamson Posted January 16, 2008 Author Share Posted January 16, 2008 Found it! Expressoion Web was inserting:  ... Thanks everyone Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441159 Share on other sites More sharing options...
bsamson Posted January 18, 2008 Author Share Posted January 18, 2008 When the header error refers to line 1 of a php file when there is an opening php tag <?php on line 1, either your file has some white space (a space, tab, newline...) before the <?php tag on line 1 or your file is saved in UTF-8 format and the BOM (byte order mark) at the start of the file is being output as content to the browser. Insure you file has nothing before the <?php tag on line 1 and make sure the file is saved in ANSI/ASCII mode. EXACTLY! Expression web was inserting the BOM .... I had to change the encoding of the page to ISO. THANKS for everyone's help! Quote Link to comment https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-442892 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.