Monday, 6 May 2013

Reading barcodes in Php


What is a bar code reader (scanner)???
Bar code reader is a hardware pluggable into computer that sends decoded bar code strings into computer. The trick is to know how to catch that received string. With PHP (and any other web programming language) the string will be placed into focused input HTML element in browser. Thus to catch received bar code string, following must be done:

just before reading the bar code, proper input element, such as INPUT TEXT FIELD must be focused (mouse cursor is inside of the input field).
once focused, start reading the code
when the code is recognized (bar code reader usually shortly beeps), it is send to the focused input field. By default, most of bar code readers will append extra special character to decoded bar code string called CRLF (ENTER). For example, if decoded bar code is "12345AB", then computer will receive "12345AB<ENTER>". Appended character <ENTER> (or <CRLF>) emulates pressing the key ENTER causing instant submission of the HTML form:


<form action="getbarcode.php" method="post">

    <input type="text" name="documentID" onmouseover="this.focus();">

</form>

The receiving form getbarcode.php is like:-



<?php
if(isset($_POST['documentID'])){

$barcode= htmlentities( $code ); 
}

?>

Here In $barcode variable, you will get the barcode value...


When choosing bar code reader, one should consider what types of bar codes will be read with it. Some bar codes allow only numbers, others will not have checksum, some bar codes are difficult to print with inkjet printers, some barcode readers have narrow reading pane and cannot read for example barcodes with length over 10 cm. Most of barcode readers support common barcodes, such as EAN8, EAN13, CODE 39, Interleaved 2/5, Code 128 etc.



No comments:

Post a Comment