慕粉3403362
2016-12-09 00:21
function code ($type,$length='4')
{
$text = array("1","2","3","4","5","6","7","8","9");
$alphabetic = array("a","b","c","d","e","f","g","h","i");
$mix = array_merge((array)$text, (array)$alphabetic);
$code = "";
switch ($type) {
case 'mix':
for ($i=1; $i<=$length; $i++) {
$code .= $mix[rand(0, count($mix)-1)];
}
break;
case 'number':
for ($i=1; $i<=$length; $i++) {
$code .= $text[rand(0, count($text)-1)];
}
break;
case 'words':
for ($i=1; $i<=$length; $i++) {
$code .= $alphabetic[rand(0, count($alphabetic)-1)];
}
break;
}
return $code;
}
$text=implode(range(0,0),range("a","z"),range("A","Z"));
$text=str_shuffle($text);
$text=substr( $text,0,4);----------------------------
$rand_color=imagecolorallocate($image,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
$xuehua=imagesetpixel($image, mt_rand(0, $width), mt_rand(0,$height), $color);
<?php
function code($type, $length = 4)
{
$num = "0123456789";
$word = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$code = "";
switch ($type) {
case 1:
for ($i = 1; $i <= $length; $i++) {
$code .= substr($num, rand(0, 9), 1);
}
break;
case 2:
for ($i = 1; $i <= $length; $i++) {
$code .= substr($word, rand(0, 51), 1);
}
break;
case 3:
for ($i = 1; $i <= $length; $i++) {
$code .= substr($num . $word, rand(0, 61), 1);
}
break;
default:
return '请选择正确的类型:1数字验证码,2字母验证码,3数字+字母验证码。';
break;
}
return $code;
}
echo code(3,5);PHP进阶篇-函数
23925 学习 · 51 问题
相似问题