Monday, June 24, 2013

PHP: QR code generator



QR code (Quick Response Code) is the trademark for a type of matrix barcode.
PHP QRcode library  can be downloaded:
 http://phpqrcode.sourceforge.net/index.php
To use  Qrcode library is quite simple, you just need to include "qrlib.php";
QRcode::png('code data text', 'filename.png') to create output file
QRcode::png('code data text') output code image directly to browser.
Example, first create a post form and post it to qrcode.php
<html>
<h1>Jiansen Lu tools -Generate QR Codes</h1><br />

<form action="qrcode.php" method="post">
Input your text here:<br />
  <textarea rows="5" cols="50" name="text1"></textarea><br />
   <input type="submit" value="Create QR Code" />
   <input type="reset"  value="Reset" name="reset" />
</form>
</html>

In qrcode.php
<?php

include "qrlib.php";

//QRcode::png('code data text', 'filename.png'); // creates file
QRcode::png($_POST['text1']); // creates code image and outputs it directly into browser

?>

Or you can directly use index.php as an example, the demo is here:
http://swf.site40.net/phpqrcode/

1 comment: