PHP - Simple QR Code Generator
Submitted by razormist on Wednesday, May 30, 2018 - 16:19.
In this tutorial we will create a Simple QR Code Generator using PHP. PHP is a server-side scripting language designed primarily for web development. Using PHP, you can let your user directly interact with the script and easily to learned its syntax. It is mostly used by a newly coders for its user friendly environment. So Let's do the coding.
There you have it we successfully created a Simple QR Code Generator using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!
Before we started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html. To use the Endroid/QR code library make sure you already installed the composer php library. Here's the link for the composer library https://getcomposer.org/. Then after installing the composer go to the command prompt and cd to your target project then after that enter this line composer require endroid/qr-code. After the installation you can now use the Endroid Librabry.Creating The Interface
This is where we will create a simple form for our application. To create the forms simply copy and write it into you text editor, then save it as shown below. index.php.- <!DOCTYPE html>
- <html lang="en">
- <head>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
- </div>
- </nav>
- <div class="col-md-3"></div>
- <div class="col-md-6 well">
- <h3 class="text-primary">PHP - Simple QR Code Generator</h3>
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="col-md-2"></div>
- <div class="col-md-8">
- <div class="form-group">
- <form method="POST">
- <input type="text" name="code" class="form-control"/>
- <br >
- <button class="btn btn-primary form-control" name="generate">Generate</button>
- </form>
- <?php
- if($_POST['code'] != ""){
- ?>
- <center><img src="generate.php?code=<?php echo $_POST['code']?>" alt=""></center>
- <?php
- }
- }
- ?>
- </div>
- </div>
- </div>
- </body>
- </html>
Creating the Generator function
This code contains the specific script for the upload. This code will generate a QR code from the Endroid/QrCode library everytime the user enter some inputs. To do that write these block of codes inside the Text editor and call it as generate.php.- <?php
- require "vendor/autoload.php";
- use Endroid\QrCode\QrCode;
- $qrCode = new QrCode($_GET['code']);
- echo $qrCode->writeString();
- ?>
Comments
Add new comment
- Add new comment
- 10154 views