Headers Already Sent

Hi all, I’m trying to do a header relocate but getting the following error. Though I cannot see what is wrong :confused:

Warning: Cannot modify header information - headers already sent by (output started at /htdocs/includes/shopping.cart.php:136) in /Volumes/Lacie 500GB External /htdocs/index.php on line 38

Please see below for shopping.cart.php…


class ShoppingCart {
    protected $items = array();
    protected $vatRate = 1.20;
    public function is_empty(){
            return true;
            return false;
    //Method for adding an item to the cart...
    public function add_items($id, $info){
        //Is it already in the cart?
            //Call the update_item() method:
            $this->update_item($id, $this->items[$id]['qty']+1);
            //Add the array of info...
            $this->items[$id] = $info;
            //Add the quantity...
            $this->items[$id]['qty'] = 1;
    public function update_item($id, $qty){
        //Delete if quantity equals 0...
        if($qty == 0):
        elseif(($qty > 0) && ($qty != $this->items[$id]['qty'])):
            //Update the quantity...
            $this->items[$id]['qty'] = $qty;

    public function update($period){

        foreach($this->items as $id=>$value):
            $hireTime = mysql_query("SELECT * FROM pricing WHERE products_id = $id AND products_timeframe = $period");
                $hire = mysql_fetch_assoc($hireTime);
                    $this->items[$id]['option'] = $hire['pricing_id'];
    //Method for deleteing an item...
    public function delete_items($id){
        //Confirm this isn't in the cart...
        if(isset($this->items[$id])):            //Remove the item...
    public function count_cart(){
        $i = count($this->items);
            return $i;

    public function cart_total(){
        foreach($this->items as $value):
            $total += $value['price']*$value['qty'];
        return $total;


    function grand_total(){

        foreach($this->items as $id=>$value):
            $price = mysql_query(sprintf("SELECT products_price FROM pricing WHERE pricing_id = %s", $value['option']));
                $cost = mysql_fetch_assoc($price);

                $multi[] = $cost['products_price']*$value['qty'];

        return number_format($total = array_sum($multi),2);

	function get_hire_period($option){
		$option = (int) $option;
			$sql = mysql_query("SELECT products_timeframe FROM pricing WHERE pricing_id = $option");
				$fetchFrame = mysql_fetch_assoc($sql);
					$_SESSION['HIRE_PERIOD'] = $fetchFrame['products_timeframe'];
	    function vatRemove($vat){
	        $base = $vat/$this->vatRate;
	        return $base;
	function delivery_price($delID){
		$del = mysql_query(sprintf("SELECT shipping_cost FROM shipping WHERE id = %f", $delID));
			$price = mysql_fetch_assoc($del);
			return $price['shipping_cost'];
	//Function to enter product details into application tables...
	function enterApplication(){
		//Insert main order details...
		$application = mysql_query(sprintf("
		INSERT INTO application_order 
		(customers_id, customers_name, customers_address, customers_telephone, customers_email, 
		coupon_code, last_modified, date_purchased, order_status, order_total, delivery_cost, 
		order_tax_rate, order_tax, ip_address) 
		VALUES('%f', '%s', '%s', '%s', '%s', '%s', now(), now(), '%f', '%f', '%f', '%s', '%f', '%s')",
		$_SESSION['USERS_EMAIL'], $_SESSION['COUPON_CODE'], '0', $this->grand_total(), $this->delivery_price($_SESSION['DELIVERY']),
		$this->vatRate, $this->grand_total()-$this->vatRemove($this->grand_total()), $_SERVER['REMOTE_ADDR']
		//Get the id of the application row...
		$insertedID = mysql_insert_id();
		//Insert products into application_products table
		foreach($this->items as $id=>$value):
		$price = mysql_query(sprintf("SELECT products_price, products_timeframe, products_price FROM pricing WHERE pricing_id = %s", $value['option']));
		    $cost = mysql_fetch_assoc($price);
		    $totalCost = $cost['products_price']*$value['qty'];
			$insertProducts = mysql_query(sprintf("
			INSERT INTO application_products
				(products_id, products_name, products_price, products_qty, products_period, products_row_total,
					VALUES ('%f', '%s', '%f', '%f', '%f', '%f', '%f')",
						$id, mysql_real_escape_string($value['name']), $cost['products_price'], $value['qty'],
						$cost['products_timeframe'], $totalCost, 


I have tried removing the viewCart method but still does not make any difference :frowning:

Any help is appreciated as always :slight_smile:

UPDATE: I have now managed to fix this. Hope no one wasted their time :confused:

You cannot create or modify certain instances of objects or resources, which require an empty output buffer, after pushing data to the screen buffer. Cookies for example can only be changed when no data has been pushed to the screen buffer. The best practice would be to devote a space at the beginning of a program/script to functionality with this strict dependency.

Modifying HTTP headers like you are doing in your script, by passing a redirect request, can only operate under the above condition too.

Warning: Cannot modify header information - headers already sent by (output started at /htdocs/includes/shopping.cart.php:136) in /Volumes/Lacie 500GB External /htdocs/index.php on line 38

Can you post the relevant lines from the index script.