#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Boston, MA USA
    Posts
    563
    Rep Power
    51

    PHP iPhone Barcode Scanner


    Hi:

    I am working on a very simple inventory program built in PHP/MySQL which uses a barcode scanner to identify products and then counts, adds, or subtracts quantities input by the user.

    I am using as a starting point, an ap called "Pic2Shop Pro" and the companion PHP code by Zone1 Creative (Pic2shop PRO | HTML5 Barcode Scanner App for iPhone iPad and Android)

    Basically, the iPhone ap is configured with a callback URL which is the processing page for the scan. The page has a button on it to initiate the scan which submits a $_GET variable called "$_GET['barcode']" The code for the button looks like this:
    PHP Code:
    <div class="scan-section" style="text-align:center">
    <a href="p2spro://scan?formats=EAN13,EAN8,UPCE,ITF,CODE39,CODE128,CODE93,STD2OF5,CODABAR,QR&callback=<?php echo urlencode($callback_url); ?>" class="btn btn-primary btn-lg">Start Scan</a>
    </div>
    I have been able to configure this so I can scan a barcode, read the $_GET variable, enter a quantity in an "input" field and submit both the barcode and the quantity to a MySQL INSERT command. Works perfectly for simply entering a quantity (counting)

    Now, I would like to be able to:
    • Scan a Product Bar Code
    • Scan a Customer Bar Code (to charge a product to a customer)
    • Enter a quantity

    The problem I have (I think) is that the scan function has only one callback url so for multiple buttons, so to differentiate one scan from another, I need to embed another $_GET variable into the button so that different data fields are assigned depending on what button is pressed.

    I tried altering the link as follows:
    Code:
    =<div class="scan-section" style="text-align:center">
    =<a href="p2spro://scan?formats=EAN13,EAN8,UPCE,ITF,CODE39,CODE128,CODE93,STD2OF5,CODABAR,QR&scn=product&callback=<?php echo urlencode($callback_url); ?>" class="btn btn-primary btn-lg">Start Scan</a>
    =</div>
    But the "scn" variable is not being read, presumably because it is going to "p2spro://scan" which doesn't know what to do with it

    How can I differentiate one scan from another to execute different parts of a logic tree? Am I even on the right track?

    All comments are welcome
    Last edited by SeanF; June 26th, 2018 at 12:42 PM. Reason: Title was missing a space
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Boston, MA USA
    Posts
    563
    Rep Power
    51
    Ah! I figured out a way... may not be the BEST way, but it works.
    I set a SESSION variable after a scan is read... depending on what session variable(s) are set, processes the result of $_GET['barcode'] differently.

    Works fine but if someone has a better solution, would be glad to know.
  4. #3
  5. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,270
    Rep Power
    4193
    Can you not just add the variable to your callback url?
    PHP Code:
    <?php

    $callback_url 
    'http://example.com/barcodeScanCallback.php?scan=product';
    ?>
    <div class="scan-section" style="text-align:center">
    <a href="p2spro://scan?formats=EAN13,EAN8,UPCE,ITF,CODE39,CODE128,CODE93,STD2OF5,CODABAR,QR&callback=<?php echo urlencode($callback_url); ?>" class="btn btn-primary btn-lg">Start Scan</a>
    </div>
    Then when the app finishes the scan and loads barcodeScanCallback.php, both $_GET['scan'] and $_GET['barcode'] should be defined.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud

IMN logo majestic logo threadwatch logo seochat tools logo