Generate An Authentication Code in PHP | PHP Tutorial For Beginners

Some time we develop a form in php like registration form, which require authentication from client side.
For this we generate an authentication code using php and send through email to the client.

This code will generate a random string that is 5 characters long. This 5 characters comes from the string that is in the for loop. We can use the database to store that string at the time of sending email and use for authentication with authentication code.

Code:-
<?php
$string = “0123456789abcdefghijklmnopqrstuvwxyz”;
for($i=0;$i<5;$i++){
$position = rand(0,36);
$str .= $string{$position};
}
echo $str;
?>

Hope this php tutorial is useful for you. Keep following www.phpcodeforbeginner.blogspot.in for more help.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>