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”
Pingback: Alan’s blog » reading barcodes on the iPhone
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!
Very nice. Thanks for providing this for us php users.
John
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):
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.
Alternative a little more complex
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
Have you found any way of avoiding a second tab following the scan and callback?
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).
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.
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.
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
Pic2Shop only seems to scan barcodes. I don’t know if there is a QR code reader with similar developer facilities.