View Full Version : another 'headers already sent' issue
CraigR
01-06-2011, 10:06 AM
My client's site has just gone live, and they are getting a ‘Cannot modify header information’ error on their items detail page.
Usually, this is a case of finding a space between tags, but in this instance, the line in question appears to be within a php block.
the (edited) error is as follows...
Notice: Undefined index: rainbowcart_4_txtgroup_0 in /xxx/items_Detail.php on line 344
Notice: Undefined index: rainbowcart_4_txtgroup_0a in /xxx/items_Detail.php on line 344
Warning: Cannot modify header information - headers already sent by (output started at /hermes/web02/b2979/moo.rainbowsite/items_Detail.php:344) in /xxx/items_Detail.php on line 405
the page itself contains 4 add to cart forms, the one loaded depends upon the database entry.
in this instance, it is form 4 causing the problem
page attached
(I find this a particular headache, as my local server and the hosting server I use for testing do not show any errors)
Ray Borduin
01-06-2011, 10:15 AM
On line 342, your loop starts at 0 when your form element names start at 1...
$i=0;
should be:
$i=1;
Jason Byrnes
01-06-2011, 10:16 AM
The blank space issue is only relevant if the headers already sent error is the first error on the page.
if there are other error on the page, those error will cause the headers already sent error.
in this case you have these errors:
Notice: Undefined index: rainbowcart_4_txtgroup_0 in /xxx/items_Detail.php on line 344
Notice: Undefined index: rainbowcart_4_txtgroup_0a in /xxx/items_Detail.php on line 344
that are causing the headers already sent error. notice also that the following line of the headers already sent error:
output started at /hermes/web02/b2979/moo.rainbowsite/items_Detail.php:344
is pointing at line 344 as the output source, same as the other errors.
So, you need to fix the errors at line 344, which are undefined index errors, meaning that the form elements you are referencing in your if statement dont exist in the post array. you need to add isset() checks to the if statement:
) && ($_POST["rainbowcart_4_txtgroup_".$i.""]) <> "") || (isset($_POST["rainbowcart_4_txtgroup_".$i."a"]) && ($_POST["rainbowcart_4_txtgroup_".$i."a"]) <> "")) {//if either of the text boxes in the pair have a value, extend the string
CraigR
01-06-2011, 10:36 AM
Many thanks to you both. - problem solved
how can i set my php.ini on my testing server to reproduce these errors, as it seems more tolerant than the live server ?
regards
Jason Byrnes
01-06-2011, 10:42 AM
in the php.ini file, set the error reporting level to E_ALL:
error_reporting = E_ALL
CraigR
01-06-2011, 10:58 AM
thanks Jason.
I checked my php.ini and this is already set
Ray Borduin
01-06-2011, 11:22 AM
You may be looking at the wrong php.ini?
In PHP 4 and PHP 5 the default value is E_ALL & ~E_NOTICE. This setting does not show E_NOTICE level errors. You may want to show them during development.
Note:
Enabling E_NOTICE during development has some benefits. For debugging purposes: NOTICE messages will warn you about possible bugs in your code. For example, use of unassigned values is warned. It is extremely useful to find typos and to save time for debugging. NOTICE messages will warn you about bad style. For example, $arr[item] is better to be written as $arr['item'] since PHP tries to treat "item" as constant. If it is not a constant, PHP assumes it is a string index for the array.
Note:
In PHP 5 a new error level E_STRICT is available. As E_STRICT is not included within E_ALL you have to explicitly enable this kind of error level. Enabling E_STRICT during development has some benefits. STRICT messages will help you to use the latest and greatest suggested method of coding, for example warn you about using deprecated functions.
vBulletin® v3.8.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.