Jump to content

Recommended Posts

 

Hi - I'm using Codeigniter 2.1.0

 

 

On my development server I do not get this problem, however, I have recently moved my site onto an ISP in a testing environment and now I am getting a nasty error:

 

 

Message:  Cannot modify header information - headers already sent by (output started at /home/jacobs15/public_html/CLFarms/system/core/Exceptions.php:185)

 

 

I have looked that the controller being called and indeed there are 3 redirects, but I do not understand why they don?t give me an error locally but they do on my remote ISP testing server,

What is also relevant is that if you reload the page the errors go away and the page loads normally.

 

 

Can someone with more experience give me advice as to where I am going wrong ?

MANY MANY THANKS !

Controller

<?php
function cart($productid=0){ 
        
  if (!isset($_SESSION['userid'])){
  $this->session->set_flashdata('error', 'You will need to login to place an order' );
  redirect('welcome/index','refresh') ;}
  
if ($productid > 0){               // IF PRODUCT PRESENT THEN ADDS TO CART 
            
  $productid = $this->uri->segment(3);
  $fullproduct = $this->MProducts->getProductUserCode($productid); 
  
    
  $this->MOrders->updateCart($productid,$fullproduct);  // UPDATE CART ADDS ONE ITEM TO CART IF THERE IS NONE AND INCREMENTS COUNT +1 IF ITEM IS IN CART ALREADY. 
  redirect('welcome/product/'.$productid, 'refresh');  
}
else{                 // GOES TO 'VIEW CART' AND SHOWS CONTENTS OF CART
  $data['title'] = "MY SITE | Shopping Cart";
  if (count($_SESSION['cart'])){
   $data['main'] = 'shoppingcart';
   $data['location'] = $this->MCustomer->GetCustomerPickupLocation(); // This delivers a full text version of the location not an ID //  
   $data['deliverydates'] = $this->MPickup->GetLocationDates($data['location']);
   $data['navlist'] = $this->MCats->getCategoriesNav();
   $this->load->vars($data);
   $this->load->view('template'); 
  }else{
   redirect('welcome/index','refresh');
  }
}
} 
?>

[/size]

Link to comment
https://forums.phpfreaks.com/topic/264853-how-do-i-fix-this-header-problem/
Share on other sites

HI Again - I should have mentioned in my earlier post that the code relating to Line 185 and causing the problem is below - It manages error reporting and output buffering :

 

 

<?php


function show_php_error($severity, $message, $filepath, $line)
   {
      $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];


      $filepath = str_replace("\\", "/", $filepath);


      // For safety reasons we do not show the full file path
      if (FALSE !== strpos($filepath, '/'))
      {
         $x = explode('/', $filepath);
         $filepath = $x[count($x)-2].'/'.end($x);
      }


      if (ob_get_level() > $this->ob_level + 1)
      {
         ob_end_flush();
      }
      ob_start();
      include(APPPATH.'errors/error_php.php');
      $buffer = ob_get_contents();
      ob_end_clean();
      echo $buffer;                                                   // <==== LINE 185 HERE
?>   }

JUst to update everyone I have solved the problem - a lesson learned really.  What I had not mentioned in my post was that I also had an 'undefined offset' error also being flagged - but I thought I'll deal with the header problem first ... thats more difficult .. the offset should be easy. So I worked away at the header problem getting no where. After all the error screamed 'Header' .. then someone told me that just because the Header error was beign triggered by line 185 in the exceptions class that did not necessarily mean it really was a header problem.

 

 

Ok .. so I went and fixed the Offset problem and in one fell swoop BINGO both problems disappeared. So lesson learned ... header problems are obtuse things and can be triggered by something quite unrelated !

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.