Demo Online
Download Code
- 5 years ago
- Zaid Bin Khalid
- 18442 Views
-
11
QR is a machine readable code with black and white blocks. QR code is the trademark for a type of matrix bar-code. It is designed in 1994 for the automotive industry in Japan. The bar-code is a machine-readable label that contains information about the item.
You can develop QR code in PHP. In this tutorial, I am going to show you how you can create a QR code in PHP. I am going to use a PHPQRCode library in this example.
Where we use QR code?
You can use this code into your banners, brochures and also on visiting cards. Most of the people know what is a QR code so you can use this anywhere. Major mobile and web application use this technology.
The PHPQRCode library features listed below:
- Supports QR Code versions (size) 1-40
- Numeric, Alphanumeric, 8-bit and Kanji encoding.
- Implemented purely in PHP, no external dependencies except GD2
- Exports to PNG, JPEG images, also exports as bit-table
- TCPDF 2-D barcode API integration
- Easy to configure
- Data cache for calculation speed-up
- Provided merge tool helps deploy the library as one big dependency-less file, simple to “include and do not worry”
- Debug data dump, error logging, time benchmarking
- API documentation
- 100% Open Source, LGPL Licensed
Example code is below.
$PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR;
//html PNG location prefix
$PNG_WEB_DIR = 'uploads/';
if(!file_exists($PNG_TEMP_DIR)){
mkdir($PNG_TEMP_DIR);
}
$filename = $PNG_WEB_DIR.time().uniqid('-QR-').'.png';
//processing form input
//remember to sanitize user input in real-life solution !!!
$errorCorrectionLevel = $_REQUEST['level'];
$matrixPointSize = $_REQUEST['size'];
//default data
$link = $_REQUEST['userdata'];
QRcode::png($link, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
HTML form code is below.
<img src="<?php echo $PNG_WEB_DIR.basename($filename); ?>" />
<form method="post">
<div class="form-group">
<label>Create QR</label>
<input type="text" name="userdata" id="userdata" class="form-control" placeholder="Enter URL and create QR" value="https://learncodeweb.com" required>
</div>
<div class="form-group">
<label>QR Code Level</label>
<select name="level" class="form-control">
<option value="L">L - smallest</option>
<option value="M" selected="">M</option>
<option value="Q">Q</option>
<option value="H">H - best</option>
</select>
</div>
<div class="form-group">
<label>QR Code Size</label>
<select name="size" class="form-control">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4" selected>4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div>
<div class="form-group">
<input type="submit" name="submit" value="Upload" class="btn btn-danger">
</div>
</form>
Demo Online
Download Code
- 5 years ago
- Zaid Bin Khalid
- 18442 Views
-
11