How to generate a random and unique alphanumeric string using PHP?
To generate random and unique alphanumeric string using PHP, you can use
md5()
and date()
functions. date()
to make string unique and md5()
to make it alphanumeric. Source Code:
<?php
function rand_alph_str($lenth) {
$ramdomStr = md5(date('YmdHis') . rand());
$lenth = ($lenth > 32) ? 32 : $lenth;
return substr($ramdomStr, rand(0, (strlen($ramdomStr) - $lenth)), $lenth);
}
?>