| 0 comments ]

// function for random string, in this function there are 6 different types of string functions are available.
they are alphanumeric,numeric,nonzero numeric,alphabets,alpha numerics with special charectors like -_#@ and unique one.

function randomKey($type = 'alphanum', $len = 8)
{
switch($type)
{
case 'alphanum' :
case 'numeric' :
case 'nonzero' :
case 'alpha' :
case 'alphanumspechar':

switch ($type)
{
case 'alphanum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'numeric' : $pool = '0123456789';
break;
case 'nonzero' : $pool = '123456789';
break;
case 'alpha' : $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'alphanumspechar': $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-#@'; break;

}

$str = '';
for ($i=0; $i < $len; $i++)
{
$str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
}
return $str;
break;
case 'unique' : return md5(uniqid(mt_rand()));
break;
}
}

0 comments

Post a Comment

Please put your comments here. your questions, your suggestions, also what went wrong with me.