All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Generate QR Code Using PHP And HTML

Last Updated : Jul 1, 2023

IN - PHP HTML | Written & Updated By - Dikshita

In this tutorial we will show you how to generate QR code using PHP and HTML, QR code is also known as Quick Response code it is a 2D barcode format code it is used to store text like phone numbers, emails, address and simple text etc.

You have to download PHP QR Code Library to generate QR code.You may also like generate barcode using PHP.

Generate QR Code Using PHP And HTML

To Generate QR Code It Takes Only Two Steps:-

  1. Make a HTML file to send text
  2. Make a PHP file to generate QR code

Step 1. Make a HTML file to send text

We make a HTML file and save it with a name qrcode.html

<html>
<body>
<div id="wrapper">
 <form method="post" action="generate_code.php">
  <input type="text" name="qr_text">
  <input type="submit" name="generate_text" value="Generate">
 </form>
</div>
</body>
</html>

In this step we create a form to send text entered by the user to storing the text and generating QR code.

Step 2. Make a PHP file to generate QR code

We make a PHP file and save it with a name generate_code.php

<?php 
if(isset($_POST['generate_text']))
{
 include('phpqrcode/qrlib.php'); 
 $text=$_POST['qr_text'];
 $folder="images/";
 $file_name="qr.png";
 $file_name=$folder.$file_name;
 QRcode::png($text,$file_name);
 echo"<img src='images/qr.png'>";
 
 //To Display Code Without Storing
 QRcode::png($text);
}
?>

In this step we get text entered by the user to store in QR code and then we include qrlib.php file which is the main file to generate code then we specify folder in which we were going to store QR code as a image and give a name to that image then we use QRcode::png() predefined function to generate QR code.

That's all, this is how to generate QR code using PHP and HTML. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

I hope this tutorial on generate qr code in php helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Dikshita

Passionate Electronics and Communication Engineering student with expertise in web development (HTML, CSS, JS,PHP, Bootstrap, React.js) and content writing. Eager problem solver and tech enthusiast, adept at creating engaging web experiences.

Follow Dikshita On Linkedin 🡪