How to Generate QR Codes using PHP
The QR codes (QR Code English) are a type of two – dimensional barcodes. Unlike a conventional bar code (eg EAN-13, Code 3 of 9, UPC), the information is encoded within a square, allowing you to store large amount of alphanumeric information.
The QR codes are easily identifiable by its square shape and the three tables located in the left upper and lower corners.
Although the initial development of the QR Codes was primarily intended for use in the automotive industry, the ability to read QR ciphers from phones and mobile devices nowadays allows the use of Qr Codes in a myriad of applications completely different from That original as can be:
- Marketing campaings
- Graphic design
- Corporate stationery (business cards, catalogs)
- Internet, websites, blogs
There are several QR code generators by the Web but if you want to go further in the matter, in this article we will see how to generate QR codes from code with PHP.
The first thing you have to do is download the library http://phpqrcode.sourceforge.net/
Unzip the package and upload it to the desired destination server. Now we can create a PHP file such as in the following:
<? Php // Set it to writable location, a place for temp files generated PNG $ PNG_TEMP_DIR = dirname (__ FILE __) DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR.; Html // prefix location PNG $ PNG_WEB_DIR = 'temp /'; include "qrlib.php"; // Ofcourse we need rights to create temp dir if (! file_exists ($ PNG_TEMP_DIR)) mkdir ($ PNG_TEMP_DIR); $ Filename = $ PNG_TEMP_DIR.'test.png '; $ MatrixPointSize = 10; $ ErrorCorrectionLevel = 'L'; $ Filename = $ PNG_TEMP_DIR.'test'.md5 ($ _ REQUEST [ 'data'] '|' $ errorCorrectionLevel '|' $ matrixPointSize....). 'Png.'; QRcode :: png ( 'information', $ filename, $ errorCorrectionLevel, $ matrixPointSize, 2); echo '<img src = "' $ PNG_WEB_DIR.basename ($ filename).. '" /> <hr />'; ?>
Where we are only displaying the image representing the QR code with the value “Information”.
We can read from any mobile device with a lectera application such as QR codes BIDI the content of our working example.