jump to navigation

Generate QR Codes with PHP November 2, 2012

Posted by Tournas Dimitrios in PHP.

Quick response codes (known as “QR” codes) are a very convenient way to display a small bit of information that is easily scanned and processed typically by mobile devices . A simpler analogy that most people are familiar with are the Universal Product codes (known as UPC codes) .  Everything you buy at the super market  has a bar-graph printed on it’s label where the  cashier will scan .  The computer then immediately interprets   the code that it picked up into product’s information (price) . Gone are the days where the cashier had to  memorize  the prices and details (discounts , offers …. ) for every single item you purchased . Think of QR codes as UPC codes but instead they’re used in a much broader spectrum , not just to identify products but to convey information of some kind . Let’s list some practical uses :

  • A popular use  of QR codes is to display website information (URL) .
  • A lot of vineyards are placing QR codes on their bottle labels .
  • When you buy an airline ticket on-line , the company sends you a QR code  that you display on the screen of your phone .  While at the airport  , the QR code (which represents your passenger information) identify your personal data .
  • Paypal Buy Now Link
  •  Email Address
  • Skype Call (Skype user name)

The major use of QR codes is to take people from the physical world to the online world . The holder of a gadget   (BlackBerry ,  Android , iPhone , Nokia , etc.) can quickly  take a  snapshot (picture) of the code and  open up a website (no need to type the URL on the small gadget ) . Anyone with a QR scanner on their phone could quickly scan that QR code  and navigate to the  website in a second or two .
QR codes could also be used to convey extra information about a specific product , so rather than writing a long text on the label of the product , an graph will embed all information . All a prospective buyer has to do is to use it’s gadget and display all extra info .

In this article I’ll show you how you can easily generate QR Codes from within your PHP application . We’ll be using PHP QR Code , a library written in PHP for generating QR Codes and which doesn’t require any dependencies beyond the standard GD graphics extension .

To find out if the GD-modul is installed/enabled  on your server , just run the phpinfo()  script in your browser . Installing the module on Linux is just one line of code , read my article . On windows (WAMP) , click on wamp’s tray icon and select php -> php_extensions ->enable php_gd2 . Finally restart your web-server . Gd library

Generating a GD-code png image is just simple as the following code  .

include "phpqrcode/qrlib.php" ;
$content = "https://tournasdimitrios1.wordpress.com" ;
QRcode::png($content) ;

Explanation :

  • Clone the PHP-library from GitHub , or download a zip file directly from this link . Copy the library into your “Library folder” and define an include statement into your code . If you downloaded a zip file (instead of cloning) , first unzip it .
  • Define the content  (URL link or a message ) –$content variable
  • generate the png-image (QRcode::png($content)

Links :


1. Kotso - November 4, 2012

thanks to you i have learned something new today, thanks a lot.

2. led - November 25, 2012

great post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s