Skip to content

navneetyadav-code/free-qr-code-generator-api-php-mysql

Repository files navigation

Free QR Code Generator API Source Code

PHP CI PHP 8.2+ MySQL Self Hosted

Self-hosted free QR code generator API and QR code manager source code built with pure PHP and MySQL. It includes static QR codes, dynamic QR redirects, scan analytics, protected QR links, verification pages, PNG/SVG/PDF export, logo support, and JSON API endpoints.

Live demo: qrcode.navneetyadav.me

This repository is for developers, agencies, students, and small teams searching for:

  • Free QR code generator source code
  • PHP QR code generator with MySQL database
  • Free QR code API source code
  • Dynamic QR code generator with analytics
  • Self-hosted QR code SaaS starter
  • cPanel QR code manager script

Why This Project

Most QR generator examples only create a single image. This project is a complete QR management app that can be hosted on regular PHP hosting and extended into a client portal, internal tool, or SaaS product.

Features

  • Static QR support for URL, Text, WiFi, vCard, Email, and SMS payloads
  • Dynamic QR support with /r/{token} redirects and editable destinations
  • Scan tracking with device, browser, OS, referrer, IP, and timeline analytics
  • QR image generation with PNG, SVG, PDF, ZIP export, colors, margins, and logos
  • Password-protected dynamic QR links
  • Public verification pages for QR authenticity
  • API key management and JSON API endpoints
  • Admin dashboard, roles, user management, pagination, filters, and CSV import
  • Secure PHP implementation with PDO prepared statements, bcrypt, sessions, CSRF protection, and rate limiting
  • Shared-hosting friendly structure with no framework, Docker, or Node build step required

Tech Stack

  • PHP 8.2+
  • MySQL 5.7+/8.0+ or MariaDB
  • Composer
  • HTML, CSS, JavaScript
  • Local Chart.js asset
  • Endroid QR Code, Dompdf, PHPMailer, Dotenv

API Examples

Generate a QR preview:

curl -X POST "https://yourdomain.com/api/generate" \
  -H "Accept: application/json" \
  -H "X-API-Key: qrm_your_api_key" \
  -F "type=dynamic" \
  -F "qr_type=url" \
  -F "destination_url=https://example.com" \
  -F "foreground_color=#111827" \
  -F "background_color=#ffffff"

Get QR statistics:

curl "https://yourdomain.com/api/stats/1" \
  -H "Accept: application/json" \
  -H "X-API-Key: qrm_your_api_key"

Record a scan:

curl -X POST "https://yourdomain.com/api/scan/{token}" \
  -H "Accept: application/json"

Project Structure

/config       App, database, and route configuration
/controllers  Request handlers
/database     Clean schema and upgrade SQL
/models       Database models
/public       Web root, assets, generated public storage
/src          Core app classes, HTTP request, services, helpers
/storage      Logs, cache, session storage
/views        PHP templates

Local Setup With XAMPP

  1. Clone the project into C:\xampp\htdocs\qr-code

  2. Install Composer dependencies:

    composer install
  3. Copy the environment file:

    copy .env.example .env
  4. Open .env and update:

    • APP_NAME=QR Control Center
    • APP_URL=http://localhost/qr-code/public
    • DB_NAME=qr_code_manager
    • DB_USER=root
    • DB_PASS=
    • set APP_KEY to any long random string
  5. Create the database and tables by importing database/schema.sql

  6. Make sure Apache mod_rewrite is enabled

  7. Browse to http://localhost/qr-code/public

  8. Register the first account. The first user is promoted to admin automatically.

Shared Hosting / cPanel Deployment

  1. Upload the project and run composer install --no-dev --optimize-autoloader, or upload the generated vendor/ folder if Composer is unavailable on the server
  2. Point your domain or subdomain document root to /public; if your host points to the project root, keep the root .htaccess file in place
  3. Create a MySQL database and import database/schema.sql
  4. Create .env from .env.example with your production values
  5. Set:
    • APP_ENV=production
    • APP_DEBUG=false
    • SESSION_SECURE=true when using HTTPS
    • APP_URL=https://yourdomain.com
  6. Ensure these folders are writable:
    • /storage/cache
    • /storage/logs
    • /storage/sessions
    • /public/storage/exports
    • /public/storage/logos
    • /public/storage/qrs

Upgrading An Existing Install

Run database/upgrade.sql on your current database to add verification fields and API key support.

CSV Import Columns

Use a CSV header like:

name,type,qr_type,url,destination_url,text,foreground_color,background_color,size,margin,custom_domain

Notes:

  • type should be static or dynamic
  • qr_type should be url, text, wifi, vcard, email, or sms
  • Dynamic rows should include destination_url
  • Static URL rows should include url

Security Notes

  • Passwords use bcrypt
  • SQL queries use prepared statements through PDO
  • CSRF protection is enabled for form submissions
  • Scan tracking is rate limited per QR/IP combination
  • Password-protected dynamic QR codes use hashed access passwords
  • Output in views is escaped with htmlspecialchars
  • .env, sessions, logs, generated QR assets, and live database dumps are excluded from Git

Good First Contributions

  • Add PHPUnit tests for services and controllers
  • Add GeoIP database integration for country/city enrichment
  • Add OpenAPI documentation for the JSON API
  • Add scheduled cleanup for old exported PDFs and rate-limit cache files
  • Improve onboarding screenshots using demo-safe sample data

Keywords

Free QR code generator, QR code generator source code, QR code API, free QR code API, PHP QR code generator, MySQL QR code manager, dynamic QR code generator, self-hosted QR code SaaS, QR code analytics, QR code tracking, cPanel QR code generator, open source QR code generator PHP.

Support The Project

If this QR code generator source code helps you, star the repository, fork it, open issues with real use cases, and share improvements through pull requests. Stars and issues help other developers find the project faster.

About

Free self-hosted QR code generator API source code in PHP and MySQL with dynamic QR analytics.

Topics

Resources

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors