Creating Simple Barcode Generator Web App in PHP Tutorial

In this tutorial we will create a Simple Barcode Generator using PHP. PHP is a server-side scripting language designed primarily for web development. Using PHP, you can let your user directly interact with the script and easily to learned its syntax. It is mostly used by a newly coders for its user-friendly environment.

So Let's do the coding.

Before we started:

First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html.

To make the barcode script work, make sure you download the barcode library in this link https://github.com/davidscotttufts/php-barcode/

And this is the link for the bootstrap that has been used for the layout https://getbootstrap.com/.

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into you text editor, then save it as index.php.

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
  5. <meta charset="UTF-8" name="viewport" content="width=device-width"/>
  6. </head>
  7. <body>
  8. <nav class="navbar navbar-default">
  9. <div class="container-fluid">
  10. <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
  11. </div>
  12. </nav>
  13. <div class="col-md-3"></div>
  14. <div class="col-md-6 well">
  15. <h3 class="text-primary">PHP - Simple Barcode Generator</h3>
  16. <hr style="border-top:1px dotted #ccc;"/>
  17. <div class="col-md-2"></div>
  18. <div class="col-md-8">
  19. <form method="POST">
  20. <div class="form-group">
  21. <label>Enter a text</label>
  22. <input type="text" class="form-control" name="barcode"/>
  23. <br />
  24. <center><button class="btn btn-primary" name="generate">Generate</button></center>
  25. <br />
  26. <?php include 'generate.php'?>
  27. </div>
  28. </form>
  29. </div>
  30. </div>
  31. </body>
  32. </html>

Creating The Main Function

This code contains the main function of the application. This script will render a barcode image when the user enter some data in the input. To create this just write these block of code inside the text editor. Save this as generate.php

  1. <?php
  2. if(ISSET($_POST['generate'])){
  3. $code=$_POST['barcode'];
  4. echo "<center><img alt='testing' src='barcode.php?codetype=code39&size=50&text=".$code."&print=true'/></center>";
  5. }
  6. ?>

DEMO

There you have it we successfully created a Simple Barcode Generator using PHP. I hope that this simple tutorial helps you to what you are looking for. For more updates and tutorials just kindly visit this site.

Enjoy Coding!!

Comments

Add new comment