Simple PHP script that generates a QR code using the popular library called PHP QR Code
. This library is open-source and easy to use. Follow these steps to create your QR code generator.
You can download the library from GitHub or directly using Composer if your project supports it.
If using Composer, run this command:
composer require endroid/qr-code
Create a new PHP file, for example, generate_qr.php
, and add the following code:
<?php require 'vendor/autoload.php'; // Ensure you have the autoload from Composer if using Composer use Endroid\QrCode\QrCode; use Endroid\QrCode\ErrorCorrectionLevel; use Endroid\QrCode\LabelAlignment; // Check if the form is submitted if (isset($_POST['text'])) { $text = $_POST['text']; // Get the text from the form // Create a QR code $qrCode = new QrCode($text); $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH()); $qrCode->setSize(300); $qrCode->setMargin(10); // Generate and save the QR code to a file header('Content-Type: image/png'); echo $qrCode->writeString(); // Output the QR code as a PNG image exit; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>QR Code Generator</title> </head> <body> <h1>QR Code Generator</h1> <form method="post" action-xhr="#"> <label for="text">Enter text or URL:</label><br> <input type="text" id="text" name="text" required> <button type="submit">Generate QR Code</button> </form> </body> </html>
generate_qr.php
file to your web server’s document root directory.http://your-server/generate_qr.php
).If you want to extend the functionality, consider adding:
You have now created a simple QR code generator using PHP! This script allows users to input text or URLs, and it generates a corresponding QR code image. Make sure your server meets the requirements for running PHP scripts, and the GD library is enabled for image handling.
PHP provides a set of functions to work with MySQL databases. As of the more…
Below is a PHP script that demonstrates how to implement pagination when displaying records from…
Below is a simple PHP script that demonstrates how to search a MySQL database table…
Transferring a WordPress site to a new domain involves several detailed steps to ensure that…
Creating client-server programs in C++ helps in understanding network programming and communication between applications over…
Creating a bookmark system for WordPress can range from simple solutions to more complex ones.…