Barcode reader

An example web page using the pic2shop barcode reading interface.

If you have an iPhone try it out at:

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" "www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="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 class="pic2shop://scan?callback=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 class=""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 thoughts on “Barcode reader

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

  2. spacer Dude Love on said:

    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!

    Reply
  3. spacer John Rodkey on said:

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

    John

    Reply
  4. spacer Michael on said:

    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.

    Reply
    • spacer alan on said:

      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=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=www.yourdom.com/yourpath/form.php?page=42&barcode=EAN
        do remember to url encode the parameters *twice* once as you build the 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.
      Reply
  5. spacer Steve on said:

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

    Reply
  6. spacer alan on said:

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

    Reply
  7. spacer Steve on said:

    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.

    Reply
  8. spacer alan on said:

    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.

    Reply
  9. spacer Steve Stofiel on said:

    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

    Reply
    • spacer alan on said:

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

      Reply

Leave a Comment Cancel reply

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

*

*

You may use these HTML tags and attributes: <a class="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>