Generate Random Serial Code in PHP

By CampCodes Administrator

Updated on:

Generate Random Serial Code in PHP

In this tutorial, we will create a Generate Random Serial Code using PHP. This code will generate a random serial code when the user clicks the button. The code uses PHP POST method to call a function that will create a casual serial system looping the given strings using for() loop. This is a user-friendly kind of program feel free to modify it.

We will be using PHP as a scripting language and interpreter that is used primarily on any web server, including xamp, wamp, etc. It is being used to any popular websites, and it has a modern technology that can easily be used by the next generation.

Getting 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.

And, this is the link for the bootstrap that I used for the layout design https://getbootstrap.com/.

Creating The Interface

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

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1" />
        <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
    </head>
<body>
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
        </div>
    </nav>
    <div class="col-md-3"></div>
    <div class="col-md-6 well">
        <h3 class="text-primary">PHP - Generate Random Serial Code</h3>
        <hr style="border-top:1px dotted #ccc;"/>
        <div class="col-md-3">
            <form method="POST">				
                <center><button class="btn btn-info" name="create">Get Serial Code</button></center>
            </form>
        </div>
        <div class="col-md-6">
                <?php include 'get_serial.php'?>
        </div>
 
    </div>
</body>
</html>

Creating the Main Function

This code contains the main function of the application. This code will create a random serial code when the button is clicked. To make this just copy and write these block of codes below inside the text editor, then save it as get_serial.php

<?php
    function GetSerialCode() {
        $strings = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
        $stringLength = strlen($strings);
        $newStrings = '';
        for ($i = 0; $i < 8; $i++) {
            $newStrings .= $strings[rand(0, $stringLength - 1)];
        }
        return $newStrings;
    }
 
    if(ISSET($_POST['create'])){
        echo '<div class="alert alert-info">MY SERIAL CODE</div>';
        echo '<center><h3 class="text-primary" style="background-color:#ccc; padding:10px;">'.GetSerialCode().'</h3></center>';
    }
 
?>
alphanumeric code auto generate number in php auto generate serial number in php auto increment serial number in php generate 4 digit random number in php generate 4 digit unique number in php generate 6 digit random number in php generate 6 digit unique random number in php generate 8 digit unique number in php generate order number php generate random number in php generate random number in php without repetition generate random number php generate random serial code in php generate random string in php generate random string in php without repetition generate unique random number in mysql generate unique random number in php mysql get random character from string php get random number php how can generate autoincrement serial number in php? how do i generate a random 4 digit number in php? how to generate random numbers in php without using rand function how to generate registration number in php how to generate unique random number in php laravel random number mt_rand in php mt_rand php mt_rand vs rand order id generator php php activation code generator php best random number generator php generate random alphanumeric string php generate random code php generate random hash php generate random number php generate random number fixed length php generate random string php generate random string fixed length php generate random string of characters php generate unique id php generate unique id for mysql php generate unique number sequence php generate unique token php get random number php guid php mt_rand php mt_rand seed php mt_rand vs rand php rand php random php random 5 digit number php random array php random array no repeat php random float php random number php random number between php random number between 1 and 100 php random number between 1 and 20 php random number between 1 and 5 php random number between range php random number generator php random number generator fixed length php random number generator script php random number in range php random string php random string from array php random_int php randomize php serial number generator script php shuffle associative array php tutorials php uniqid php unique id php unique id generator php unique id numbers only php unique identifier for a computer rand function in php random 4 digit number generator random code generator in php random function in php random int php random number generator random number generator in codeigniter random number generator in php random number generator in php mysql random number generator php random number generator php code random number php random password generator php w3schools random php random string generator random string generator php random string php random_string php unique random number generator php code uuid_create php what is built in function for generating random alphanumeric? which of the following is a php function used to get random numbers? wordpress generate unique id

Leave a Comment