Headers not working live

Works perfectly on localhost but wont redirect live.
The redirect function is

function redirect_to($location = NULL){
	if ($location != NULL) {
		header("Location: {$location}");
		exit;
	}
}

and one of the pages not working is

<?php
	$pid = $_POST['id'];
	$q = $_POST['qty'];

	// if($pid<1 or $q<1) return;

	if(is_array($_SESSION['cart'])){
		// if(product_exists($pid)) return;
		if(product_exists($pid)){
			$max=count($_SESSION['cart']);
			for($i=0;$i<$max;$i++){
				if($_SESSION['cart'][$i]['productid'] == $pid){
					$_SESSION['cart'][$i]['qty'] = $_SESSION['cart'][$i]['qty'] + $q;
				}
			}
		}else{
			$max=count($_SESSION['cart']);
			$_SESSION['cart'][$max]['productid']=$pid;
			$_SESSION['cart'][$max]['qty']=$q;
		}		
	}
	else{
		$_SESSION['cart']=array();
		$_SESSION['cart'][0]['productid']=$pid;
		$_SESSION['cart'][0]['qty']=$q;
	}
	redirect_to("viewcart.html");
?>

Thanks in advance for the help

On the live server tun on error reporting or add this bit to the top of you’re script.


ini_set("error_reporting", E_ALL ^ E_NOTICE); 
ini_set("display_errors", 1); 

I suspect that headers have been sent meaning that there is white space or a BOM being sent before the header redirect.

Cheers that was it. Been a while since doing php on a live server totally forgot about that stuff

Thanks