PHP Headers

I am having some trouble with conflicting headers in Wordpress and a QR Code class that I am trying to use. I am a bit lost on how headers operate even, so I’m sure that is part of the problem. Basically this class uses the following code to print the QR Code:


header("Content-type: image/png");
print $img;
return true;

However, upon trying to use the header tag, I am getting the following error due to Wordpress:

Warning: Cannot modify header information - headers already sent by (output started at /home/bgmh1986/public_html/site/wp-content/themes/toolbox/header.php:13) in /home/bgmh1986/public_html/site/wp-content/themes/toolbox/php/BarcodeQR.php on line 86

Due to the following area in the header.php of Wordpress:


<!--[if IE 6]>
<html id="ie6" <?php language_attributes(); ?>>
<![endif]-->
<!--[if IE 7]>
<html id="ie7" <?php language_attributes(); ?>>
<![endif]-->
<!--[if IE 8]>
<html id="ie8" <?php language_attributes(); ?>>
<![endif]-->
<!--[if !(IE 6) | !(IE 7) | !(IE 8)  ]><!-->
<html <?php language_attributes(); ?>>
<!--<![endif]-->
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width" />

I have tried putting the header call from the barcode in this area, but it just prints out a bunch of random characters (as I assume it’s uncertain of the media type it is trying to display). How would I go about modifying the headers at this point down the page? Thanks.

If the whole point of BarcodeQR.php is to display an image then you should remove all the code that does not pertain to the QRcode. Should have nothing of Wordpress headers and what have you.

The BarcodeQR.php just uses the google chart API to generate a QRCode so it is a pretty basic set of function calls. I assume it needs the header call to interpret the data is it printing, as this is my output for the function currently (when the header call is commented out):


&#65533;PNG

&#65533;&#65533;&#65533;
IHDR&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;c&#65533;&#65533;&#65533;&#65533;bKGD&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;IDATx&#65533;&#65533;&#65533;&#65533;N&#65533;0&#65533;Q&#65533;&#65533;&#65533;_n,&#546;-&#65533;uq&#65533;:&#65533;Q&#65533;d&#65533;&#1785;^&#65533;&#1479;&#65533;&gt;&#65533;&#65533;&#65533;2!&#65533;	&#65533;L&#65533;gB&lt;&#65533;&#964;x&&#65533;3!&#65533;	&#65533;L&#65533;gB&lt;&#65533;&#964;x&&#65533;3!&#65533;	&#65533;L&#65533;gB&lt;&#65533;&#964;x_&#65533;&#1530;&#65533;&#65533;&#65533;j?&#65533;+&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;J&#65533;:U
W`;
&#65533;L&#65533;gB&#65533;&#697;&#65533;.&#65533;~5&#65533;D&#65533;&#828;&#65533;&#65533;&#65533;&#65533;$G!&#65533;	&#65533;L&#65533;&#65533;5&#65533;E&#65533;&#65533;&#65533;&#65533;&#65533;T&#65533;;V}&#65533;B&#65533;B<&#65533;ob.|J&#65533;&#65533;&#65533;&#65533;&#65533;(&#65533;3!&#65533;	&#65533;sa&#65533;&#65533;o&#65533;&#65533;&#65533;g"&#65533;?&#65533;&#65533;&#964;x&&#283;&#65533;&#65533;&#25962;&#65533;/r&#65533;&#65533;&#65533;&#65533;(&#65533;3!&#65533;	&#65533;&#65533;&#142;u"&#65533;g&#65533;&#65533;&#65533;Kw&#65533;&#2036;&#65533;%&#65533;Q&#65533;gB<&#65533;]&#65533;&#65533;&#65533;dt&#65533;&#65533;q&#65533;&#964;xO&#65533;/&#65533;X&#65533;&#65533;&#65533;&#65533;s&#65533;&#65533;u&#65533;Ms&#65533;&#65533;&#964;x&&#283;&#65533;_&#65533;Z&#65533;r&#65533;|f&#65533;{&#65533;&#65533;S&#65533;&#65533;&#65533;&#65533;&#964;x&&#283;xF:y&#65533;&#750;&#65533;&#65533;&#65533;a&#65533;B<&#65533;&#65533;&#65533;&#65533;&#65533;>/"&#65533;&#65533;j&#65533;h&#65533;&#65533;R&#65533;&#65533;&#65533;o&&#65533;3!&#40880;&#65533;2&#65533;&#65533;4&#65533;&#65533;&#65533;{&#65533;~&#65533;&#964;x&#65533;{*&#65533;&#1511;&#65533;~v&#65533;&#65533;&#65533;z&#65533;&#65533;3!&#65533;	&#65533;&#989;&#65533;&#65533;{':&#65533;&#65533;?/u&#65533;&#964;x&#65533;&#65533;H&#65533;&#65533;1&#65533;&#65533;&#65533;&#65533;&#829;`&#65533;{&#65533;&#65533;&#65533;&#65533;8
&#65533;L&#65533;gB&#65533;&#65533;&#65533;w&#65533;[8&#65533;L&#65533;B&#65533;2!&#65533;	&#65533;N&lt;&#65533;&#65533;sG;&#65533;&#65533;&#65533;B&#65533;gB&lt;&#65533;&#65533;ky&#65533;&#65533;&#65533;s&#65533;&#65533;&#65533;a8
&#65533;L&#65533;gB&lt;&#65533;{&#65533;3:&#1449;&#65533;~&#65533;&#65533;B&#65533;gB&lt;&#65533;&#65533;k&#65533;&#65533;&#65533;]d&#65533;&#65533;	g&#65533;9
&#65533;L&#65533;gB&#65533;&#65533;^&#65533;&#65533;q6i&#65533;&#65533;p&#65533;&#65533;&#964;x&&#65533;#&#837;&#65533;&#65533;&#65533;&#65533;f&#65533;&#65533;x&&#65533;3!&#65533;&#65533;kV&#65533;y?&#65533;&#65533;&#65533;&#65533;7&#65533;Q&#65533;gB&lt;&#65533;&#65533;k&#65533;&#65533;qN&#65533;&#65533;=&#65533;g&#65533;8
&#65533;L&#65533;gB&#65533;&#65533;&#65533;k&#65533;&#65533;&#964;x&&#65533;3!&#65533;	&#65533;L&#65533;gB&lt;&#65533;&#964;x&&#65533;3!&#65533;	&#65533;L&#65533;gB&lt;&#65533;&#964;x&&#65533;3!&#65533;	&#65533;L&#65533;gB&lt;&#65533;}&#65533;(rQry&#879;&#65533;&#65533;&#65533;&#65533;IEND&#65533;B`&#65533;

Which I assume is a png if interpreted correctly.

The BarcodeQR.php just uses the Google Chart API apparently to create this QR code. This seems simple enough at the bottom of this page http://code.google.com/apis/chart/infographics/docs/post_requests.html . However it still utilizes the header() function which is messing with Wordpress.

Got it! Just wanted to update on how the problem was solved. I used the following method:

<img src=“qrgenerate.php” /> where qrgenerate.php was the code used on the main page to generate the image via method calls of BarcodeQR. This allowed the header to be specified in a separate action.