vincej Posted June 27, 2012 Share Posted June 27, 2012 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] Quote Link to comment https://forums.phpfreaks.com/topic/264853-how-do-i-fix-this-header-problem/ Share on other sites More sharing options...
vincej Posted June 27, 2012 Author Share Posted June 27, 2012 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 ?> } Quote Link to comment https://forums.phpfreaks.com/topic/264853-how-do-i-fix-this-header-problem/#findComment-1357531 Share on other sites More sharing options...
Mahngiel Posted June 28, 2012 Share Posted June 28, 2012 The error is not in the core, it's actually in your error scripts. Your application is trying to display one of the 4 errors (db, general, php, or 404) but your code is failing. Take a look at those to debug the problem. Quote Link to comment https://forums.phpfreaks.com/topic/264853-how-do-i-fix-this-header-problem/#findComment-1357762 Share on other sites More sharing options...
RalphLeMouf Posted June 29, 2012 Share Posted June 29, 2012 as I'm new with these concepts, I could be missing it, but I didn't see any relationships to my code and the error scripts. I also looked in the errors section of the config.php file and could see anything there Quote Link to comment https://forums.phpfreaks.com/topic/264853-how-do-i-fix-this-header-problem/#findComment-1357999 Share on other sites More sharing options...
vincej Posted June 29, 2012 Author Share Posted June 29, 2012 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 ! Quote Link to comment https://forums.phpfreaks.com/topic/264853-how-do-i-fix-this-header-problem/#findComment-1358000 Share on other sites More sharing options...
Pikachu2000 Posted June 30, 2012 Share Posted June 30, 2012 Error notices generate output. There can't be any output before sending headers. Quote Link to comment https://forums.phpfreaks.com/topic/264853-how-do-i-fix-this-header-problem/#findComment-1358044 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.