Jump to content

[SOLVED] Headers Already Sent Problem with PEAR Image_Barcode


fj1200

Recommended Posts

Just 'discovered' what PEAR is all about and really want to use it, but having trouble incorporating it into any web pages. 

 

If I run

<?php
require_once("Image/Barcode.php");
$bc = new Image_Barcode;
$bc->draw($_GET['NUM'], $_GET['TYP'], $_GET['IMG']);
?>

 

It works perfectly and I get an image.  If I try to imcorporate that into a web page I get:

 

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\barcode.php:2) in C:\wamp\php\PEAR\Image\Barcode.php on line 104

‰PNG ??? IHDR???P???2???ñãο???PLTE???ÿÿÿ¥ÙŸÝ???2IDATxœc(q Œw-qeeyæ8?3o¤Ã™ó£á̸çp&ßmateó.¡??f/ÅÚŽM?????IEND®B`‚

 

I've looked up these errors, tried a few things but can't see a problem.  And - yes, I've had a hunt around this very forum too and yes - read the Headers thread at the top of this forum.  Still can't see it.

 

I've tried

 

image_barcode::draw

 

and get the same problem.  Can anyone suggest a solution?  One of the issues is white space - that all looks ok unless I'm looking in the wrong place.  Everything works a treat except this.

 

Link to comment
Share on other sites

I've tried a few things:

 

  • Adding it in directly to the top of the page as per the 1st code snippet
  • print ("<img src=\"barcode2.php&NUM='$_Shortcode'&TYP='code39'&IMG='PNG'\">"); (this just produces an image placeholder)
  • Image_Barcode::draw( ... )

 

Various things.  I even got into trouble with wifey on Saturday night for playing with it when I'm NOT supposed to be working! 

 

I can't do anything about the header being sent from the PEAR module - and I'm not that good at ph anyway.

Link to comment
Share on other sites

print ("<img src=\"barcode2.php&NUM='$_Shortcode'&TYP='code39'&IMG='PNG'\">");

 

That should be the proper way to do it. Did you look at the generated source code to see if it was all right?

 

See if you can embed it this way into plain HTML file.

Link to comment
Share on other sites

Don't mean to be thick but I've got to have something wrong somewhere.  None of this works...

 

Ths barcode2.php file that calls the PEAR ext. works fine -

 

http://<servername>/barcode2.php?NUM=9780131471498&TYP=code39&IMG=png

 

<?php
require_once"C:\wamp\php\PEAR\Image\Barcode.php";
$bc = new Image_Barcode;
$bc->draw($_GET[NUM], $_GET[TYP], $_GET[img]);
?>

 

However if I try to then call that from the code below I just get an image placeholder. 

 

<html>
<?php
$Shortcode = "12345";
print ("<img src=\"barcode.php?NUM=9780131471498&TYP=code39&IMG=png\">");
?>
</html>

 

<html>
<img src="barcode2.php?NUM=123&TYP=code39&IMG=png">
</html>

 

Tried with quotes, without quotes, haven't tried it backwards yet though....  :-[

 

If I can nail this one then the next one I want to try is the graphing one, then the data grid.  These are 3 I've been looking for for ages and will make a real difference to me.

 

Link to comment
Share on other sites

Yup - that's got ot.

 

Also changed the way I generate the barcode ; I'm now using

 

<?php

require_once ('Image/Barcode.php');

Image_Barcode::draw($_GET[NUM], 'int25', 'png');

?>

 

Seems to work better for me.

 

Many thanks for your assistance Mchl.  Hopefully I can crack the others now!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.