Random Number generator in php - Mostlikers

09 August, 2013

Random Number generator in php

Generally the Random number is used for some authentication purpose.In most of the websites like gmail ,just dial the users while login the security code will be send to the mobile for the secure purpose.

random-number-generator

What is mean by random number ?

Random number is nothing but a unique code that automatically create some unique code numbers. It is used to generate a random number within a specific range of numbers.

Where we use this coding ?

This coding is used in sms verification codes , captcha , forget password, comments verification for the purpose of authentications to check the user. 

Coding  

<?php
$Random_code=rand();
echo $Random_code;
?>

Sample Program
 

<?php
if(isset($_POST['submit']))
{
$code1=$_POST['code1'];
$code=$_POST['code'];
if($code1!="$code")
{
$msg="Invalide code";
}
else
{
$msg="Your code is correct";
}
}
?>
<form name="form" method="post">
<p>Type Below this code <?php $Random_code=rand(); echo $Random_code; ?> </p><br />
<p>Enter the random code<br />
<input type="text" name="code1" title="random code" />
<input type="hidden" name="code" value="<?php echo $Random_code; ?>" />
</p>
<p><input type="submit" value="check" title="code check" name="submit" /></p>
</form>
<p><?php if(isset($_POST['submit']))
{ echo $msg; } ?>
</p>

No comments:

Post a Comment