输出六个随机字符串

HTML代码

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 7     <title>Document</title>
 8 </head>
 9 <body>
10     <form action="verificaiton.php" method="POST" enctype="multipart/form-data">
11         验证码类型:<input type="text" name="types"><input type="submit" value="提交">
14     </form>
15 </body>
16 </html>

PHP代码

<?php
header("content-type:text/html;charset=utf-8");
$type = $_POST["types"];//接收提交过来的值
function type($type){//封装函数
$types = ["number","string","mixin"];//限制输入的类型
if(in_array($type,$types)){//判断是否在限制的类型里
    $number = "1234567890";//存所有的数字
    $string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";//存所有的字母
    $mixin = $number.$string;//存字母和数字
    $number = str_shuffle($number);//打乱所有的数字
    $string = str_shuffle($string);
    $mixin = str_shuffle($mixin);    
    if($type == number){//判断如果输入的是数字类型
        $colorVer = substr($number, 0,6);//截取前六位数字
        $colorVer = str_split($colorVer);//将数字字符串转成数组
        foreach ($colorVer as $key => $value) {//遍历数组
            $a = mt_rand(0,225);//存每个颜色的随机值
            $b = mt_rand(0,225);
            $c = mt_rand(0,225);
            echo "<font style=' color: rgb($a,$b,$c)'>$value</font>";//给数字数组的每个值添加随机颜色并输出
        }
    }else if($type == string){
        $colorVer = substr($string, 0,6);
        $colorVer = str_split($colorVer);
        foreach ($colorVer as $key => $value) {
            $a = mt_rand(0,225);
            $b = mt_rand(0,225);
            $c = mt_rand(0,225);
            echo "<font style=' color: rgb($a,$b,$c)'>$value</font>";
        }
    }else{
        $colorVer = substr($mixin, 0,6);
        $colorVer = str_split($colorVer);
        foreach ($colorVer as $key => $value) {
            $a = mt_rand(0,225);
            $b = mt_rand(0,225);
            $c = mt_rand(0,225);
            echo "<font style=' color: rgb($a,$b,$c)'>$value</font>";
        }
    }
}else {//如果所输入的值不在所限制的类型里,则提示请输入、、、并返回到输入界面
    echo "<script>";
    echo "alert('请输入number、string或mixin');";
    echo "window.location.href='ver.html';";
    echo "</script>";
}

}
type($type);
?>

 

转载于:https://www.cnblogs.com/yuxiaoge/p/10685970.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值