Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\ecommerce\base\classes\baseconfig.php:23) in C:\wamp\www\ecommerce\base\classes\adminHelper.php on line 6
I know the root cause for the above warning. But iam not able to reslove it. My problem is different from other questions and many down-voted and closed topics.
The warning page is : index.php, is the only page that im dealing with displaying and Setting data. this warning is shown when i called header('Location') on helper adminHelper.php
Im using a class coreConfig.php which sets and gets the data for the index page.
- And some helper classes too.
with the index page im using the same form , Same functions , same routines for setting data in a form. only data changes with the passed argument. and this page works perfectly with all other set of data, except for one.showing the above warning. i cannot figure it out why this happens. im formatting the output by using this function
public $mainTabLength = "\t";
public $tabLength = "\t\t";
public function printFormat($text, $class) {
if($this->useDivToPrint) {
echo $this->mainTabLength . "<div class=\"$class\">" . $this->tabLength . "$text\n";
echo $this->mainTabLength . "</div>\n";
}
else{
echo $text;
}
}
I dont want to use buffering of the codes too .. awaiting comments .
Note : I had formatted my php code by removing any white-spaces from the IDE
Update :
The problem was solved by inspecting the buffer output.As expected my code was setting some header information already before im calling header('Location'). But i was sure that i was not doing such a mistake, because my all other piece of data is working fine. But i was surprised to see the output of buffer for working set of data and the one that caused the warning :
form 1: adding new category (working fine header('Location')) even i can see the following header information already sent :
<!DOCTYPE HTML>
<html>
<head>
<title>E-Commerce</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<link href="../css/style.css" media="screen" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="../images/favicon.png"/>
<script type="text/javascript" language="javascript" src="../jses/jquery-1.11.3.min.js"></script>
<script type="text/javascript" language="javascript" src="../jses/scripts.js"></script>
<script type="text/javascript" language="javascript" src="../jses/datePicker.js"></script>
form 2: adding new product (not working header('Location') causing warning) i can see the same header information already sent :
<!DOCTYPE HTML>
<html>
<head>
<title>E-Commerce</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<link href="../css/style.css" media="screen" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="../images/favicon.png"/>
<script type="text/javascript" language="javascript" src="../jses/jquery-1.11.3.min.js"></script>
<script type="text/javascript" language="javascript" src="../jses/scripts.js"></script>
<script type="text/javascript" language="javascript" src="../jses/datePicker.js"></script>
This was the root cause that i was not able to detect a problem with my code. why it worked for my form1 even though it already sent some header information already !!