• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

Random Code in PHP

joswayy

Ad Optimization Ninja
J Rep
0
0
0
Rep
0
J Vouches
0
0
0
Vouches
0
Posts
132
Likes
65
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 2 900 XP
If you are looking for on how to create Random Code in PHP then you are at the right place. In this tutorial, we are going to learn on how to create random code using PHP. You can use it this simple project in your existing web application or systems like in registration form, before sending information you can use the random code to confirm it before sending data to the database or you can use it as a random code for your selling items in POS web project, etc.

Take a look the source code below.

This simple code, we are going to use it to have a random code. This source code where we can get a random code.

  1. <?php
  2. $code_variable

    =

    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz0123456789"

    ;
  3. ?>

Full Source Code
  1. <?php

  2. function

    randomCode(

    )
  3. {
  4. $code_variable

    =

    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz0123456789"

    ;
  5. srand

    (

    (

    double)

    microtime

    (

    )

    *

    1000000

    )

    ;
  6. $i

    =

    0

    ;
  7. $rand_Code

    =

    ''

    ;
  8. while

    (

    $i

    <=

    7

    )
  9. {
  10. $num

    =

    rand

    (

    )

    %

    33

    ;
  11. $tmp

    =

    substr

    (

    $code_variable

    ,

    $num

    ,

    1

    )

    ;
  12. $rand_Code

    =

    $rand_Code

    .

    $tmp

    ;
  13. $i

    ++;
  14. }

  15. return

    $rand_Code

    ;
  16. }

  17. ?>

And, we have to create a button for the refreshing of the page, so we can get easily a new code on the web page.

  1. <a

    href

    =

    "index.php"

    >
  2. <button

    type

    =

    "button"

    >
  3. Get New Code
  4. </

    button

    >
  5. </

    a

    >

Lastly, this source code where we can display the random code that we get in the PHP query above.

  1. <div

    style

    =

    "width:30%;"

    >
  2. <b

    >
  3. <?php echo randomCode(

    )

    ; ?>
  4. </

    b

    >
  5. </

    div

    >

Output

random-code.jpg



Download
You must upgrade your account or reply in the thread to view the hidden content.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,501

351,827

351,841

Top