Dynamically generating a QR code using PHP Last Updated : 04 Apr, 2024 Comments Improve Suggest changes Like Article Like Report There are a number of open source libraries available online which can be used to generate a Quick Response(QR) Code. A good open source library for QR code generation in PHP is available in sourceforge. It just needs to be downloaded and copied in the project folder. This includes a module named "phpqrcode" in which there is a file named "qrlib.php". This file must be included in the code to use a function named 'png()', which is inside QRcode class. png() function outputs directly a QR code in the browser when we pass some text as a parameter, but we can also create a file and store it. Syntax: QRcode::png($text, $file, $ecc, $pixel_Size, $frame_Size); Parameters: This function accepts five parameters as mentioned above and described below: $text: This parameter gives the message which needs to be in QR code. It is mandatory parameter. $file: It specifies the place to save the generated QR. $ecc: This parameter specifies the error correction capability of QR. It has 4 levels L, M, Q and H. $pixel_Size: This specifies the pixel size of QR. $frame_Size: This specifies the size of Qr. It is from level 1-10. Example 1: PHP program to generate QR Code. php <?php // Include the qrlib file include 'phpqrcode/qrlib.php'; // $text variable has data for QR $text = "GEEKS FOR GEEKS"; // QR Code generation using png() // When this function has only the // text parameter it directly // outputs QR in the browser QRcode::png($text); ?> Output: Note: This output is directly generated in the browser. This code will not run on an online IDE because it can't include 'phpqrcode' module. Example 2: PHP program to generate QR Code and create file. php <?php // Include the qrlib file include 'phpqrcode/qrlib.php'; $text = "GEEKS FOR GEEKS"; // $path variable store the location where to // store image and $file creates directory name // of the QR code file by using 'uniqid' // uniqid creates unique id based on microtime $path = 'images/'; $file = $path.uniqid().".png"; // $ecc stores error correction capability('L') $ecc = 'L'; $pixel_Size = 10; $frame_Size = 10; // Generates QR Code and Stores it in directory given QRcode::png($text, $file, $ecc, $pixel_Size, $frame_Size); // Displaying the stored QR code from directory echo "<center><img src='".$file."'></center>"; ?> Output: Note: The output of both examples are different. In the first example, the output will display in default frame and pixel size which is generated directly on browser whereas the output of the second example is a 'png' file with pixel and frame size as 10 stored in a directory. Comment More infoAdvertise with us Next Article Dynamically generating a QR code using PHP A AvinashMishra25 Follow Improve Article Tags : Web Technologies PHP PHP Programs Similar Reads Generating Random String Using PHP Generating a random string involves creating a sequence of characters where each character is selected unpredictably from a defined set (e.g., letters, numbers, symbols). This process is used in programming to produce unique identifiers, passwords, tokens, or keys for security and randomness in appl 2 min read How to generate a random, unique, alphanumeric string in PHP There are many ways to generate a random, unique, alphanumeric string in PHP which are given below: Table of ContentUsing str_shuffle() FunctionUsing md5() FunctionUsing sha1() FunctionUsing random_bytes() FunctionUsing random_int() in a Custom FunctionUsing uniqid() with more_entropy parameterUsing 4 min read How to Upload Image into Database and Display it using PHP ? Uploading the image/videos into the database and displaying it using PHP is the way of uploading the image into the database and fetching it from the database. Using the PHP code, the user uploads the image or videos they are safely getting entry into the database and the images should be saved into 8 min read How to Convert Byte Array to String in PHP? Given a Byte Array, the task is to convert the byte array to a String in PHP. It is used in various scenarios, such as processing binary data, handling file uploads, or working with data transmission protocols. Below are the approaches to convert byte array to string in PHP:Table of ContentWhat is a 3 min read Google reCAPTCHA Integration in PHP In this article, we are going to discuss how to integrate Google reCAPTCHA v2 in PHP.Approach:Register your site at Google reCAPTCHASubmit HTML formGet response key at server sideRe-verify the key and give response to user end.Step 1: Register your site at Google reCAPTCHA â Register your website at 3 min read How to Change Background Image with PHP? We are going to dynamically change background images on webpages using PHP. Incorporating a dynamic background image on a web page can improve user experience and provide personalized content based on different conditions. Below are the approaches to change the background image using PHP: Table of C 3 min read Generating OTP (One time Password) in PHP Now these days, OTP (one time password) is mandatory in almost each and every service. A developer can generate OTP in many ways but the challenge is not to be predictive as any one can predict the OTP and can exploit the service. Some of popular format of OTPs are: 4 or 6 digit Numeric OTP. 4 or 6 2 min read PHP Program to Print Diamond Shape Star Pattern Printing a diamond-shaped star pattern is a classic programming exercise that involves nested loops to control the structure of the pattern. In this article, we will explore different approaches to creating a PHP program that prints a diamond-shaped star pattern. Using Nested LoopsThe basic method i 2 min read PHP Programs PHP Programs is a collection of coding examples and practical exercises designed to help beginners and experienced developers. This collection covers a wide range of questions based on Array, Stirng, Date, Files, ..., etc. Each programming example includes multiple approaches to solve the problem.Wh 7 min read How to generate an XML file dynamically using PHP? A file can be generated using PHP from the database, and it can be done by the static or dynamic method in PHP. Static methods can be called directly - without creating an instance of a class. Here we are going to discuss how to create an XML file dynamically.The first thing we need to do is fetch t 2 min read Like