您的位置:首页 > 编程语言 > PHP开发

PHP验证码登录实例

2015-12-17 01:03 633 查看
转自:http://blog.chinaunix.net/uid-20344928-id-3425140.html

通过random生成随机数,然后保存在session里:

session_start();

function random($length, $numeric = 0) {
mt_srand((double)microtime() * 1000000);
if($numeric) {
$hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1));
} else {
$hash = '';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$max = strlen($chars) - 1;
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
}
return $hash;
}

$seccode = random(4, 1);

$_SESSION['seccode'] = $seccode;
$seccode = sprintf('%04d', $seccode);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: