Infolinks

Breaking

Adsense

Thursday, January 28, 2016

GENERATE RANDOM CODE IN PHP: Create a Random Code From A-Z a-z 0-9

Hi there! Today I created by own version in generating random code in PHP from characters A-Z, a-z and 0-9. You can set how many characters to display by setting it in the variable $limit. You can use this one to generate random passwords.

PHP Code Random Code Generator

<?php
$string="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";//62 is the length of the string. You can check the length of a string using
//strlen($string) function
$limit=10;
$i=0;
$code="";
while($i<$limit)
{
$rand=rand(0,62);
$code=$code.$string[$rand];
$i++;
}
echo $code;
?>

The code above will return 10 random characters from the $string and will generate something like the output below.

Sample Output Random Code Generator

fBicU0qbbG / m8I3h7FEjU

Try the Random Code Generator in PHP Live here!




Thank you for visiting and hope this helps you. Feel free to leave a comment below for any questions. I got some other articles related to php and mysql here in my blog. Watch out for more upcoming tutorials related to blogging and programming. Good day! ^_^

GENERATE RANDOM CODE IN PHP: Create a Random Code From A-Z a-z 0-9


No comments:

Post a Comment

Adbox