SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: PHP Headers

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2011
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    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:
    Code:
    <!--[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.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    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.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Enthusiast
    Join Date
    May 2011
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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):

    Code:
    �PNG
    
    ���
    IHDR������������c����bKGD�������������IDATx����N�0�Q���_n,Ȣ-�uq�:�Q�d�۹^�ׇ�>���2!�	�L�gB<�τx&�3!�	�L�gB<�τx&�3!�	�L�gB<�τx_�׺���j?�+������J�:U
    W`;
    �L�gB�ʹ�.�~5�D�̼����$G!�	�L��5�E�����T�;V}�B�B<�ob.|J�����(�3!�	�sa��o���g"�?��τx&ě��敪�/r����(�3!�	��Žu"�g���Kw�ߴ�%�Q�gB<�]���dt��q�τxO�/�X����s��u�Ms��τx&ě�_�Z�r�|f�{��S����τx&ěxF:y�ˮ���a�B<�����>/"��j�h��R���o&�3!龰�2��4���{�~�τx�{*�ק�~v���z��3!�	�ϝ��{':��?/u�τx��H��1����̽`�{����8
    �L�gB���w�[8�L�B�2!�	�N<��sG;���B�gB<��ky���s���8
    �L�gB<�{�3:֩�~��B�gB<��k���]d��	g�9
    �L�gB��^��q6i��p��τx&�#ͅ����f��x&�3!��kV�y?����7�Q�gB<��k��qN��=�g�8
    �L�gB���k��τx&�3!�	�L�gB<�τx&�3!�	�L�gB<�τx&�3!�	�L�gB<�}�(rQryͯ����IEND�B`�
    Which I assume is a png if interpreted correctly.

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2011
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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/in..._requests.html . However it still utilizes the header() function which is messing with Wordpress.

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2011
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •