Barcode reader

An example web page using the pic2shop barcode reading interface.

If you have an iPhone try it out at:

http://www.meandeviation.com/test/iphone/barcode.php
<?php
$code = $_REQUEST['ean'];
echo '<' . '?xml version="1.0" encoding="UTF-8" ?' . '>';
?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>test barcode reader</title>
</head>
<body>
<div>
<h1>test barcode reader</h1>
<?php
 if ( $code ) :
?>
<p>
The barcode was <?php echo htmlentities( $code ); ?>
</p>
<?php
 endif;
?>
<p>
<a href="pic2shop://scan?callback=http://www.meandeviation.com/test/iphone/barcode.php?barcode=EAN">read barcode</a>
</p>
<p>
This web page is for iPhone users only and needs
<a href=""http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=308740640&mt=8">pic2shop</a>
installed (it is free), which allows third party web apps and iPhone apps to use its bar code reading software as a form of local web service.
</p>
</div>
</body>
</html>

19 thoughts on “Barcode reader

  1. Pingback: Alan’s blog » reading barcodes on the iPhone

  2. I think it would be a great idea to incorporate barcode labels in to more everyday life. Have seen that the iphone has app’s that you can download to scan and compare prices of food online, as well as an app that tells you the content of the food. Great start, just hope they keep developing the idea!

  3. Alan, I appreciate this code and I know you’re busy but how would I get the results from the scan to populate a field in a webform. It’s just a text box and I need to return the value into it.

    • The barcode reader invokes a URL, so the only way I know to populate the web form field is to use a back-end script as follows:

      First the simplest way, make it the first field that the user can enter (wizard like):

      1. start of with a page (let’s say start.html”) that just has a link that says “select barcode” or something that has the “pic2shop: link in (as in the example)
      2. set the callback to point to your own script say:
        pic2shop://scan?callback=http://www.yourdom.com/yourpath/dobarcode.php?barcode=EAN
        where “dobarcode.php” is the name of your scrip (or dobar.py” if you do python, etc.
      3. make the script dobarcode.php generate a web page with the form with the first barcode field already filled in with the barcode returned by pic2shop

      Alternative a little more complex

      1. create a script “form.php” that generates a form (say with fields barcode, page, comment). The script should also be readytyo accept parameters to pre-fill the various fields, so that: form.php?barcode=123456789&page=20&comment=hello+world would pre-populate the relevant fields
      2. the form has a ‘choose’ barcode link (possibly only if there is no barcode given, or maybe just after it to change it)
        However, instead of a direct link to pic2shop, the link should invoke some javascript on the web page. The script should take the content of any of the form fields except the one for the barcode, then generate a URL with them prefilled and the barcode one with barcode=EAN (for pic2shop) as before.

        for example, if the user had already filled in the page number field with 42, but no comment, then the Javascript should create the url:
        pic2shop://scan?callback=http://www.yourdom.com/yourpath/form.php?page=42&barcode=EAN
        do remember to url encode the parameters *twice* once as you build the http://www.yourdom.com/ url, and oncde when you encode this URL to make ot the callback parameter for pic2shop

      3. when pic2shop has scanned the barcode your form.php scriop will be called again, this time with the page and the barcode set, so the form would be ready of the remaining usre input
      4. your form then has a standard submit button to do whatever you like with.
  4. In the example the callback is to the same web page that it starts on, with just the barcode number displayed. However, the callback can be a different script, which can then do anything you want, for example, redirect to the Amazon page for the book (maybe after 13 to 10 character ISBN conversion).

  5. Thanks Alan. If I understand you correctly, if the url is the same it will stay in the same tab but if it is different it will open a new tab (iPone Safari). My problem is that I’m using jQuery Mobile and the URL contains a # which seems to be causing a problem. I’ll do some experiments.

  6. Ah, I see what you mean. When I do it it creates a fresh tab too!

    On desktop browser the JavaScript in two tabs would be able to ‘talk’ to each other by seeing each others variables as they come form the same domain. This should then mean that the new tab is be able to close the old one … but not sure how that works on iPhone Safari.

  7. Has anyone gotten Pic2Shop to return the data from a QRCode using the callback url syntax?

    I am using FileMakerGo and can get EAN style barcodes to work. I replaced EAN in the callback url with QR, QRC, QRCODE and nothing seems to work. Are QRCodes even supported with the callback url?

    -Steve

    • I have only tried it on iPhone, but there is nothing iPhone specific in my code.

      When I first blogged about it there was no web example on the pic2shop site, but now they have a web example.

      I note that the pic2shop web example says iPhone only, so I wonder whether the ability to for a web page to link to an app url scheme is only supported on the iPhone.

  8. Hi Alan,

    Does this code specifically scan certain barcodes?

    I am having trouble scanning CODE39 format barcodes, is this because of any code omitting those formats?

    Thanks

    John

  9. Thanks, nice solution.

    I tried it on my Samsung Galaxy Note 2. temporary now pic2shop is supported on Android too.

    But after pic2shop reads my code it crashes during the callback to my site.

    Do you have any mind on it ?

  10. ok i found the mistake,

    the first line should be $code = $_REQUEST[‘barcode’];

    then everything will be nice.
    So much thanks .

Leave a Comment

Your email address will not be published. Required fields are marked *