为了账号安全,请及时绑定邮箱和手机立即绑定

这样写对吗?

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;

}


正在回答

2 回答

$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);

0 回复 有任何疑惑可以回复我~
<?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);


3 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

这样写对吗?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信