How to Build QR Code Generator Site With PHP QR CODE library

Programming Tutorials – will share the article on how to build a QR code generator site with php qr code library. Perhaps you’ve visited several sites like,,, etc , and you think, how do we build it. We can create qr code generator site with the help of php qr code libraries or using Google’s API chart. Both library or API can be used free of charge and easy to use. The difference is if you build qr code with php qr code library, the entire control stand beside you, in contrast with google chart API, you need to use a third party site. In this article I will be more focus on the use of QR CODE PHP Library.


Before going any further how to create a QR Code generator site, it helps to understand the sense of qr code. QR Code (Quick Response Code) is the development of a Barcode created by Japanese corporation Denso-Wave in 1994. Unlike a barcode that only one side of it containing the data, QR Code has two sides that contain data, and this makes the QR Code more contain information than barcodes. As for example, as follows:

How To Build QR Code Generator Site With PHP QR CODE Library Example

Easy Ways to create qr code using PHP QR CODE library

According to official site php qr code, PHP QR Code is open source (LGPL) library for generating QR Code, 2-dimensional barcode. Based on libqrencode C library, provides API for creating QR Code barcode images (PNG, JPEG thanks to GD2). Implemented purely in PHP, with no external dependencies (except GD2 if needed).

Lets begin the tutorial

1. Download library php qr code here.
2. Your server must support PHP with gd image library (php5-gd). For installation has been much discussed.
3. Create a folder as qrcode, then copy the folder phpqrcode (phpqrcode library in zip form) that has been extracted into the folder qrcode.
4. There are 2 ways to create qr code image, the first qr code image created temporary and qr code image made permanent. We just need QRcode::png function to create the barcode images

By default QRcode::png function have a standard parameters as follows

static QRcode::png
( $text,
$outfile = false,
$level = QR_ECLEVEL_L,
$size = 3,
$margin = 4,
$saveandprint = false

With the following explanation

  • String $text text string to encode.
  • String $outfile (optional) output file name, if false outputs to browser with required headers.
  • Integer $level (optional) error correction level QR_ECLEVEL_L, QR_ECLEVEL_M, QR_ECLEVEL_Q or QR_ECLEVEL_H.
  • Integer $size (optional) pixel size, multiplier for each ‘virtual’ pixel.
  • Integer $margin (optional) code margin (silent zone) in ‘virtual’ pixels.
  • Boolean $saveandprint (optional) if true code is outputed to browser and saved to file, otherwise only saved to file. It is effective only if $outfile is specified.

For more details you can directly read from the official site

a. Creating temporary qr code image.

For example, create a php file as temporary.php and copy the following code:

 <?php include('phpqrcode/qrlib.php'); QRcode::png(''); ?>

the example above create qr code image as follows :

How To Build QR Code Generator Site With PHP QR CODE Library Example

a. Creating permanently qr code.


    define('EXAMPLE_TMP_SERVERPATH', dirname(__FILE__).'/temp/');
    define('EXAMPLE_TMP_URLRELPATH', 'phpqrcode/temp/');
 $email = ''; 
 $subject = 'question'; 
 $body = 'please write your question here'; 
 $codeContents = 'mailto:'.$email.'?subject='.urlencode($subject).'&body='.urlencode($body); 

 QRcode::png($codeContents, $tempDir.'023.png', QR_ECLEVEL_L, 3); 
 echo '<img src="'.EXAMPLE_TMP_URLRELPATH.'023.png" />'; 

From the example above, you would create qr code image permanently with the name 023.png in the folder phpqrcode > temp

5. To build the qr code generator site, I chose the first way, which makes qr code image temporary. Demo application in the following link.

QR Code Generator Site Demo

In the demo above, I use jquery and bootstrap framework so that the interface look more attractive and mobile responsive.

Tutorial to build qr code generator site using php qr code library, jquery and Bootstrap framework

a. Create an index.php and copy the following script.

<!DOCTYPE html>
 <title>Free Online QR Codes Generator -</title>
 <link href="" rel="stylesheet" integrity="sha256-MfvZlkHCEqatNoGiOXveE8FIwMzZg4W85qfrfIFBfYc= sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
 <link rel="stylesheet" href="style.css">

<div class="wrapper">

<div class="container content">

<div class="row">

<div class="col-xs-12 col-md-6">

<h3 class="header-h3">QR CODE GENERATOR</h3>

<div class="tab-content">

<div class="form-group">
 <label class="label-form">Free text</label>
 <input type="text" class="form-control" id="data" placeholder="Free text for share">



<div class="col-xs-12 col-md-6">-->

<div class="col-xs-12 col-md-6">

<h3 class="header-h3">QR CODE RESULT</h3>

 <input type="hidden" class="form-control" id="hiddendata">

<div id="hasil"></div>


<div class="col-xs-12 col-md-6">-->


<!-- container content-->

<script src=""></script>
<script src="" integrity="sha256-Sk3nkD6mLTMOF0EOpNtsIry+s1CsaqQC1rVLTAy+0yc= sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>
<script type="text/javascript">
 $( document ).ready(function() {
 $( "#data" ).keyup(function() {
 var formData = {data:$("#hiddendata").val()}; 
function getdata(formData){
 url : "parameter.php",
 type: "POST",
 data : formData,
 success: function(data, textStatus, jqXHR)
 error: function (jqXHR, textStatus, errorThrown)

b. Create new php file as data.php and copy the following script.

<?php $data = $_GET['data']; include('phpqrcode/qrlib.php'); $codeContents = base64_decode($data); QRcode::png($codeContents, false, QR_ECLEVEL_L, 10); ?>

c. Create new php file as parameter.php and copy the following script.

$data = base64_encode($_POST['data']);
echo '<center><img src="http://'.$_SERVER['SERVER_NAME'].'/data.php?data='.$data.'" /></center>'; 

d. Create new CSS file as style.css and copy the following script.

 font: normal 16px/20px 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Geneva, Verdana, sans-serif;
 margin-top: 15px;
#hasil img{
 max-width: 300px;
 -moz-box-shadow: 3px 3px 3px 3px #ccc;
 -webkit-box-shadow: 3px 3px 3px 3px #ccc;
 box-shadow: 3px 3px 3px 3px #ccc;
 font-weight: 100!important;
 padding: 10px;
.form-group {
 margin-bottom: 5px;
 padding: 10px;
 background-color: green;
 color: white;
 background: transparent;
 border: none;
 border-bottom: 1px dashed #83A4C5;
 box-shadow: 0 0 0 8px rgba(255,255,255,0.5);
 outline: none;
 padding: 0px 0px 0px 10px;
.form-control:focus, textarea:focus{
 border-bottom: 1px dashed #83A4C5;
 box-shadow: 0 0 0 8px rgba(255,255,255,0.5);
 outline: 0 none;
 border-top: 1px solid #BEC8CC;
 font-size: 12px;
 margin-top: 20px;
 padding-top: 20px;
.footer a{
.footer a:hover{
 text-decoration: none!important;
 margin-top: 10px;

Voila, you’ve managed to create qr code generator site by your self. To download the full script please on the following link

Before finishing this article, I’ll discuss a little bit how to use google chart API to create qr code image

Google provides APIs that can be used to create qr code with the following syntax.

Supporting parameters as follows :

cht=qr : Specifies a QR code.
chs=<width>x<height> : Image size.
chl=<data> : Required The data to encode. Data can be digits (0-9), alphanumeric characters, binary bytes of data, or Kanji. You cannot mix data types within a QR code. The data must be UTF-8 URL-encoded. Note that URLs have a 2K maximum length, so if you want to encode more than 2K bytes (minus the other URL characters), you will have to send your data using POST.

As example below :

it will show image like below

Using QR CODE from google chart API

Another related article :

How To Create QR CODE Image After Published New Article WordPress

Thus article about How to Build QR Code Generator Site With PHP QR CODE library , hope useful 🙂

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.


 Add your comment
  1. how to save diffrent name qrcode in folder

  2. Hi, I am trying to accomplish something with QR codes and cannot grasp how to do this on a WordPress site. Basically, for every new blog post, I would like a QR code automatically generated to link to that post address, however, I do not want it to display on the page. Rather I want it to be saved to a folder on the server with the filename corresponding to the blog post ID so that it can be retrieved later. Is this possible?

  3. Url not work in your site demo – blank image QR

  4. Hi! there is some problem in this script. i had use this on my website but when put any type of data like url then result not shown. can you guide me what can i do ?

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

%d bloggers like this: