Jump to content

[SOLVED] Header error ...


bsamson

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/86330-solved-header-error/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441111
Share on other sites

<?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.

Link to comment
https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441114
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441116
Share on other sites

<?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

Link to comment
https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441124
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-441139
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/86330-solved-header-error/#findComment-442892
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.