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);
}转载请注明来源地址:小川编程 » https://www.youhutong.com/index.php/article/index/227.html
1、本站发布的内容仅限用于学习和研究目的.请勿用于商业或非法用途,下载后请24小时内删除。
2、本站所有内容均不能保证其完整性,不能接受请勿购买或下载,如需完整程序,请去其官方购买正版使用
3、本站联系方式Email:admin@youhutong.com ,收到邮件会第一时间处理。
4、如侵犯到任何版权问题,请立即告知本站(立即在线告知),本站将及时删除并致以最深的歉意
