开发中生成随机混合字符应用于方方面面,以下片段利用php生成一个16位的随机token并输出:
<?php
function creatToken($len,$chars=null){
if(is_null($chars)){
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
}
mt_srand(1000*(double)time());
$str = '';
for($i = 0,$lc = strlen($chars)-1;$i<$len;$i++){
$str.= $chars[mt_rand(0,$lc)];
}
return $str;
}
$token = creatToken(16);
echo $token;
?>
Comments | NOTHING