// 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;
}
}
[Monday, May 12, 2008
|
0
comments
]
Popular Posts
- php questions
- some php questions
- How to create a plugin in elgg.
- php Questions
- Mysql query for searching a value, add weightage on the number of occurances and sort based on the weight-age
- Contact Me
- solving the packaging problem in PHP
- How to add or remove WWW on URLs using htaccess.
- php questions
- Inserting nodes into xml files using XML DOM in PHP .
0 comments
Post a Comment
Please put your comments here. your questions, your suggestions, also what went wrong with me.