zoukankan      html  css  js  c++  java
  • 输出六个随机字符串

    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);
    ?>
  • 相关阅读:
    Ios插件开发
    React-Native学习指南
    APP测试基本流程
    iOS开发-由浅至深学习block
    你真的会用UITableView嘛
    iOS系统右滑返回全局控制方案
    优化UITableViewCell高度计算的那些事
    UITableViewCell高度自适应探索--AutoLayout结合Frame
    UITableView优化技巧
    页面间跳转的性能优化(一)
  • 原文地址:https://www.cnblogs.com/yuxiaoge/p/10685970.html
Copyright © 2011-2022 走看看