Alan’s blog

December 22, 2009

Barcode reader

Filed under: — alan @ 6:40 pm

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>

11 Comments »

  1. [...] Their developer documentation has an example iPhone app, but not an example web page.  However, I made a web page using their interface in about 5 minutes (see PHP source of barcode reader). [...]

    Pingback by Alan’s blog » reading barcodes on the iPhone — December 22, 2009 @ 7:11 pm

  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!

    Comment by Dude Love — June 11, 2010 @ 2:01 pm

  3. Very nice. Thanks for providing this for us php users.

    John

    Comment by John Rodkey — July 14, 2010 @ 5:53 pm

  4. 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.

    Comment by Michael — June 21, 2011 @ 11:51 am

  5. 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.

    Comment by alan — June 21, 2011 @ 5:04 pm

  6. Have you found any way of avoiding a second tab following the scan and callback?

    Comment by Steve — July 20, 2011 @ 2:41 am

  7. 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).

    Comment by alan — July 20, 2011 @ 8:08 am

  8. 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.

    Comment by Steve — July 20, 2011 @ 4:15 pm

  9. 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.

    Comment by alan — July 20, 2011 @ 4:44 pm

  10. 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

    Comment by Steve Stofiel — October 21, 2011 @ 7:16 pm

  11. Pic2Shop only seems to scan barcodes. I don’t know if there is a QR code reader with similar developer facilities.

    Comment by alan — October 21, 2011 @ 7:33 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress