Header Errors


#1

I get this error:
Warning: Cannot add header information - headers already sent by (output started at /home/blasto333/phppointofsale.com/html/PHP_Point_Of_Sale_7.0/sales/delete.php:9) in /home/blasto333/phppointofsale.com/html/PHP_Point_Of_Sale_7.0/sales/delete.php on line 73

This is happening because of calling header (“location: sale_ui.php”);
after the portion of the document, but I need to redirect to there. I only get an error on PHP 4.1.2 but not on my install of 4.3.4. Any suggestions? [code below]

[code]

<?php session_start(); ?> <?php /* Program: PHP Point Of Sale Author: Chris Muench Last Updated: Feburary 21, 2004 File: sales/delete.php

Description:
*/

include ("…/settings.php");
include ("…/classes/db_functions.php");
include ("…/classes/security_functions.php");

$dbf=new db_functions($cfg_server,$cfg_username,$cfg_password,$cfg_database,$cfg_tableprefix,$cfg_theme);
$sec=new security_functions($dbf,‘Sales Clerk’);
if(!$sec->isLoggedIn())
{
header (“location: …/login.php”);
exit();
}

if(isset($_GET[‘action’]))
{
$action=$_GET[‘action’];
switch($action)
{
case $action==‘all’:
$sec->closeSale();
break;
case $action==‘item’:
$pos=$_GET[‘pos’];

		for($k=0;$k<count($_SESSION['items_in_sale']);$k++)
		{
			if($k==$pos)
			{
				unset($_SESSION['items_in_sale'][$k]);
				$_SESSION['items_in_sale']=array_values($_SESSION['items_in_sale']);
				
				if(count($_SESSION['items_in_sale'])==0)
				{
					$sec->closeSale();
				}
				break;
			}
		
		}
		break;
		
	case $action=='item_search':

		unset($_SESSION['current_item_search']);
		
		break;
		
	case $action=='customer_search':
		unset($_SESSION['current_customer_search']);
		
		break;
}

}

header (“location: sale_ui.php”);

$dbf->closeDBlink();

?>

[/code]

#2

I beleive that header information must be sent BEFORE you close the in the HTML. Or you can use the HTML meta refresh tag to redirect to another page (That is how I usually do it.)


#3

thats what I ended up doing. Thanks.


#4

Another way is to use output buffering (ob_start() ) to make PHP collect all of your output before it sends anything to the client. This should allow you to add headers at any point in the page.


#5

Additionally,

Note: HTTP/1.1 requires an absolute URI as argument to Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER[‘HTTP_HOST’], $_SERVER[‘PHP_SELF’] and dirname() to make an absolute URI from a relative one yourself.

Make sure that “Location:” has an http(s?)://servername in it.