admin管理员组文章数量:1130349
以下是使用 PHP 编写的生成永远唯一的密钥码、激活码的自定义方法函数:
/**
* 生成永远唯一的密钥码
* sha512(返回128位) sha384(返回96位) sha256(返回64位) md5(返回32位)
* 还有很多Hash函数......
* @author xiaochaun
* @param int $type 返回格式:0大小写混合 1全大写 2全小写
* @param string $func 启用算法:
* @return string
*/
function create_secret($type=0, $func='sha512')
{
$uid = md5(uniqid(rand(),true).microtime());
$hash = hash($func, $uid);
$arr = str_split($hash);
foreach($arr as $v){
if($type==0){
$newArr[]= empty(rand(0,1)) ? strtoupper($v) : $v;
}
if($type==1){
$newArr[]= strtoupper($v);
}
if($type==2){
$newArr[]= $v;
}
}
return implode('', $newArr);
}
以下是使用 PHP 编写的生成永远唯一的密钥码、激活码的自定义方法函数:
/**
* 生成永远唯一的密钥码
* sha512(返回128位) sha384(返回96位) sha256(返回64位) md5(返回32位)
* 还有很多Hash函数......
* @author xiaochaun
* @param int $type 返回格式:0大小写混合 1全大写 2全小写
* @param string $func 启用算法:
* @return string
*/
function create_secret($type=0, $func='sha512')
{
$uid = md5(uniqid(rand(),true).microtime());
$hash = hash($func, $uid);
$arr = str_split($hash);
foreach($arr as $v){
if($type==0){
$newArr[]= empty(rand(0,1)) ? strtoupper($v) : $v;
}
if($type==1){
$newArr[]= strtoupper($v);
}
if($type==2){
$newArr[]= $v;
}
}
return implode('', $newArr);
}
版权声明:本文标题:使用 PHP 制作生成永不重复的密钥码、激活码等案例教程 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/jiaocheng/1735000850a1284862.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论