A unique site ID can be created in PHP using the uniqid () function. This function has two parameters we can set. The first is the prefix. This is what will be appended to the beginning of each ID. The second is more_entropy. If this is false or not specified it will return 13 characters, if it is true then 23 characters will be returned.


<?php 
//creates a unique id with the 'about' prefix $a = uniqid(about); echo $a; echo "<br>";
?>
creates a longer unique id with the 'about'
<?php
$b = uniqid (about, true); Echo $b; echo "<br>";
?>
creates a unique ID with a random number as a prefix - more secure than a static prefix
<?php
$c = uniqid (rand (),true); echo $c; echo "<br>";
?>
this md5 encrypts the username from above, so its ready to be stored in your database
<?php
$md5c = md5($c); echo $md5c;
?>
Unique id using Time Function
<?php $t=time(); echo($t); ?>
and a function to customize lenth
<?php
# Genareting Non Matching Uniq IDs -------------------------------
function uniqgen($prefix, $lenght){
$random_pred = md5(base64_decode(RAIN_HASH_SALT.rand(00000000,99999999).date("F j, Y, g:i a").time().RAIN_HASH_PASS));
$hashcoderend = strtoupper(pbkdf2("SHA256", $random_pred, RAIN_HASH_PASS, 1000, $lenght, false));
return $prefix.$hashcoderend;
}
echo uniqgen("R",10);
?>

0 comments:

Post a Comment

 
Top
Blogger Template