How to generate Qrcode Using Codeigniter?

Today, We want to share with you qr code codeigniter.In this post we will show you codeigniter barcode, hear for membuat barcode dengan codeigniter we will give you demo and example for implement.In this post, we will learn about PHP Barcode Generator Tutorial with an example.

Today Tutorial about is how to generate qrcode using Codeigniter. So firstly we know about what is the QR Code.

What is Qr Code ?

QR stands for quick response it’s another form of bar code but some significant difference between them while barcodes hold full details only in the horizontal direction, QR codes stores full details in both direction horizontally as well as vertically. In QR code we can store full details like web url, email, phone number, Address or any types of the set strings etc.

Read Also:  Get custom product attributes in Woocommerce

Full details of Qr code is decoded using dedicated QR code scanner or Qr code decoding Application.

jQuery Ajax QR Code Generator PHP script Download
jQuery Ajax QR Code Generator PHP script Download

If you are looking for a How To Create BarCode generator using PHP then you must go through with this step by step tutorial.

So let’s starts the Codeigniter coding sections.

Library

i use PHPQRCODE library for generating the QR code.So you can download the library using this link PHP QR CODE Library Download

View

qrcodetext.php
And then i Make the view file for enter the text and generate the QR code from this text

<!DOCTYPE html>
<html>
<head>
	<title>php qrcode generator - www.pakainfo.com</title>
</head>
<body>
<h2>How to generate QR Code using Codeigniter - www.pakainfo.com</h2>
<form action="<?php echo base_url();?>QrController/qrcodeGenerator" method="post">
<input type="text" name="phpqrcode_input">
<button>Submit</button>
</form>
</body>
</html>

Some brief description of the Qrcontroller.php file

Read Also:  php add array to array - Append One Array To Another In PHP

i can Load the Php QR Code library in the constructor of the controller

Qrcontroller.php

function __construct ()
{	
  parent::__construct();
  $this->load->library('phpqrcode/qrlib');
  $this->load->helper('url');
}

Next i get the entered text and generate the QR Code

public function qrcodeGenerator ( )
{
		
    $phpqrcode_data = $this->input->post('phpqrcode_input');	
    if(isset($phpqrcode_data))
    {
	
         $SERVERFILEPATH = $_SERVER['DOCUMENT_ROOT'].'/qrcode-generation-in-codeigniter/uploads/';
	 $text = $phpqrcode_data;
	 $string_qr= substr($text, 0,9);	
	 $directory = $SERVERFILEPATH;
	 $phpqrcodefilenm1 = $string_qr."-Qrcode" . rand(2,200) . ".png";
	 $phpqrcodefilenm = $directory.$phpqrcodefilenm1;
	 QRcode::png($text,$phpqrcodefilenm);		
	 echo"<center><img src=".'http://www.your-domain-name.com/qrcode-generation-in-codeigniter/uploads/'.$phpqrcodefilenm1."></center";
    }
    else
    {
	echo 'No Text Entered';
    }	
}

  • $phpqrcode_data – Inputted text that can be encoded in QR Code
  • $SERVERFILEPATH – Path of server where QR Images to be stored
  • $phpqrcodefilenm1 – Name of QR uploads file
  • QRcode::png($text,$phpqrcodefilenm) – Using QRcode::png() function we generate QR code it takes two parameter first one is entered text and 2nd is the name of the QR image file.
Read Also:  Custom Pagination Using WooCommerce REST API

Controller

QrController.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
 
class Welcome extends CI_Controller 
{
 
	function __construct ()
	{	
		parent::__construct();
		$this->load->library('phpqrcode/qrlib');
		$this->load->helper('url');
	}
 
	public function index()
	{
		$this->load->view('qrcodetext.php');
	}
 
	public function qrcodeGenerator ( )
	{
		
		
		$phpqrcode_data = $this->input->post('phpqrcode_input');
		
		if(isset($phpqrcode_data))
		{
 
			//file path for store uploads
		    $SERVERFILEPATH = $_SERVER['DOCUMENT_ROOT'].'/qrcodeci/uploads/';
			$text = $phpqrcode_data;
			$string_qr= substr($text, 0,9);
			
			$directory = $SERVERFILEPATH;
			$phpqrcodefilenm1 = $string_qr."-Qrcode" . rand(2,200) . ".png";
			$phpqrcodefilenm = $directory.$phpqrcodefilenm1;
			QRcode::png($text,$phpqrcodefilenm);
			
			echo"<center><img src=".base_url().'uploads/'.$phpqrcodefilenm1."></center";
		}
		else
		{
			echo 'No Text Entered';
		}	
	}
}

Dynamic QR codes Generator in Laravel 5.7
Dynamic QR codes Generator in Laravel 5.7