Online QR Code Generator In PHP

This tutorial is about how to create QR code using PHP and qrserver.com API. You generate QR code easily for that. Let's see how we do it. First create file name as class.QR.action.php and write down this code.

<?php
class QRform
{

public function Myform()
{
echo '<center>QR Code Creator -Make Your Name, website, phone number, location QR Code Free</center>';
echo '<div class="comments"><i class="fa fa-edit"></i>&nbsp;Type Here</div>';
echo '<form method="post">';
echo '<i class="fa fa-list"></i>&nbsp;Type name/url/phone number or any text:<br/><input type="text" name="qrtext" required/><br/>';
echo '<i class="fa fa-arrows-v"></i>&nbsp;Height:<br/>';
echo '<input name="height" type="number" value="300"><br/>';
echo '<i class="fa fa-arrows-h"></i>&nbsp;Width:<br/>';
echo '<input name="width" type="number" value="200"><br/>';
echo '<input type="hidden" name="s" value="1">';
echo '<br/><input type="submit" value="Generate">';
echo '</form>';
}
public function MyHeader()
{
header("Content-type: text/html; charset=UTF-8");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
echo '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">';
echo '<html lang="en" xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en">';
echo '<head>';
echo '<title>Online Free QR Code Generator</title>';
echo '<link rel="stylesheet" type="text/css" href="styles.css">';
echo '<meta name="description" content="QR Code Creator -Make Your Name QR, website QR, phone number QR, location QR Code Free">';
echo '<meta name="author" content="Sajjad Hossain Hira">';
echo '<meta name="keywords" content="QR Code, QR Code Generator, QR Code Maker, Onlie QR Maker"/>';
echo '<meta name="robots" content="ARCHIVE"/>';
echo '<meta name="revisit" content="1 day"/>';
echo '<meta name="robots" content="index,follow"/>';
echo '<meta name="googlebot" content=”index"/>';
echo '<meta name="Slurp" content=”index"/>';
echo '<meta name="msnbot" content=”index"/>';
echo '<meta name="DISTRIBUTION" content="GLOBAL"/>';
echo '</head>';
echo '<body>';
echo '<div class="menu">';
echo '<a href="?"><div class="tab"><i class="fa fa-home"></i>&nbsp;Home</div></a>';
echo '<a target="_blank" href="http://facebook.com/sajjadhossainhira"><div class="tab"><i class="fa fa-users"></i>&nbsp;Facebook</div></a>';
echo '<a target="_blank" href="https://play.google.com/store/apps/details?id=me.scan.android.client"><div class="tab"><i class="fa fa-file"></i>&nbsp;Download QRscaner apk</div></a>';
echo '</div>';
}
public function MyFooter()
{
echo '<div class="footer">';

echo '<a target="_blank" href="./qr.zip"><i class="fa fa-file"></i>&nbsp;Download This Script free</a><br/>';
echo '<b>&copy;2015 <a target="_balnk" href="https://phpans.com"><i class="fa fa-tag"></i>&nbsp; phpAns.com</a>';
echo '</div>';
}
}
?>
Now create another file for setup all classes, we are going to write this file name as class.QR.php

<?php
class QRWriter
{
public $title;
public $text;
public $height;
public $width;
public function __construct($Mytext,$Myheight,$Mywidth)
{
if(empty($Mytext))
$Mytext = 'http://facebook.com/sajjadhossainhira';
if($Myheight<100)
$Myheight = 100;
if($Mywidth<100)
$Mywidth = 100;

$this->text = urlencode($Mytext);
$this->height = urlencode($Myheight);
$this->width = urlencode($Mywidth);
}

public function MakeQR()
{
echo '<div style="padding:5px 5px;background-color: black;color:green;text-align:center;">QR Code Generated Successfully</div>';
$MyTime = time();
$dir = 'data';
if(!is_dir($dir)){
mkdir($dir);
chmod($dir,0777);
}
$newQR = 'data/phpans.com_'.$MyTime.'.jpg';
$url = 'https://api.qrserver.com/v1/create-qr-code/?data='.$this->text.'&size='.$this->height.'x'....;
copy($url,$newQR);
echo '<br/><br/><center><img src="'.$newQR.'"><br/><br/><br/><a href="'.$newQR.'" target="_blank"><i class="fa fa-arrow-down"></i>&nbsp;Download</a></center>';
}

public function __destruct()
{

}
}
?>
After completing this our script almost ready. Now we are going to create index.php, Create this file and write down this code.
index.php 


<?php
include("class.QR.php");
include("class.QR.action.php");
$myObject = new QRform();
$myObject->MyHeader();
$myObject->Myform();
if(isset($_POST['qrtext']) && isset($_POST['s']) && $_POST['s']==1)
{
$WriteQR = new QRWriter(strip_tags($_POST['qrtext']),$_POST['height'],$_POST['width']);
$WriteQR->MakeQR();

}
$myObject->MyFooter();
?>
Now we need to create a stylesheet for this snippet. Create a file name as styles.css and write down this styles into the script. 

This scirpt is now ready for use, now we are goig to see live demo about this.

@import url('icons/css/font-awesome.min.css');


body {

font-family: candara, Tahoma, Geneva, sans-serif;
font-size:17px;
color: green;
background: #F5F5F5;


}
input,textarea,select
{
background-color:#FFFFFF;
color: #000000;
border: 1px solid green;
padding: 10px;
font-size: 20px;
}
a {
color: teal;
text-decoration: none;
}
a:hover
{
color: red;
text-decoration: small;
}
.divNav
{
background-color: #FFFFFF;
color:#FFF;
padding: 5px 5px;
}
table
{
background-color: #585858;
color: #FFF;
padding: 5px 5px;
margin: auto;
}
.td1
{
border-right: 1px solid #454545;
}
.comments
{
background-color: #FFFFFF;
margin: 5px;
color: #000000;
padding: 7px;
}
.menu{
background-color:#FFFFFF;
text-align:center;
}
.menu a
{
color: red;
}

.tab {
display:inline;
background-color: #FFFFFF;

}

/* Media for larger devices */
@media screen and (min-width: 800px) {
.tab {
padding: 10px 15px;
margin: 5px;
display:inline;
background-color: #F5F5F5;
border: 2px solid #3B99D1;
}
.tab:hover
{
background-color: #3879D9;
-webkit-animation: myfirst 2s; /* Chrome, Safari, Opera */
-moz-animation: myfirst 2s; /* Chrome, Safari, Opera */
animation: myfirst 2s;
}
.menu{
background-color:#FFFFFF;
text-align:center;
margin-right: 3px;
margin-bottom: 10px;
padding: 20px 20px;
}
.menu a
{
color: #3B99D1;
}

.menu a:hover
{
color: #FFFFFF;
-webkit-transition: color 500ms ease-out 1s;
-moz-transition: color 500ms ease-out 1s;
-o-transition: color 500ms ease-out 1s;
transition: color 500ms ease-out 1s;
}


}

/* Chrome, Safari, Opera */
@-moz-keyframes myfirst {
from {background: #FFFFFF;}
to {background: #3879D9;}
}
/* Chrome, Safari, Opera */
@-webkit-keyframes myfirst {
from {background: #FFFFFF;}
to {background: #3879D9;}
}

/* Standard syntax */
@keyframes myfirst {
from {background: #FFFFFF;}
to {background: #3879D9;}
}
.footer
{
background-color:#FFFFFF;
text-align:center;
margin-right: 3px;
margin-bottom: 10px;
padding: 10px 10px;
text-align: center;
}
This scirpt is now ready for use, now we are goig to see live demo about this.

Download Source Code
Unlock source code with a social share.

Did you like this article? it will be appreciated if you share a coffee or burger with the author

Sent $5 to the author
Sent $10 to the author

Need Assistance?

I'm Sajjad Hossain, working on web application development since 2012. Do you need assistance on your project? or are you stuck with problems? I am available to help you.
If you want to contact with me ping me at -

WhatsApp
Skype


We use cookies on our website. To find out more about how and why they are used or opt-out, please read our Cookie Policy. By choosing "I Accept", you consent to our use of cookies. Cookie Policy
Top