简单的验证码

    科技2022-07-16  118

    <?php //a-z 0-9 A-Z 进行密码包装 $ary = [0,1,2,3,4,5,6,7,8,9]; $a = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]; $A = [A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,]; $a1 = array_merge($ary,$a,$A); //将数组合并成一个好随机 $ay = ''; //准备一个空的字符串 $ay .= $a1[mt_rand(0,61)] .$a1[mt_rand(0,61)].$a1[mt_rand(0,61)].$a1[mt_rand(0,61)]; //阿拉伯数字 + 子母大小写 组成的4为数字 ?> <h1 id="z"><?php echo $ay ?></h1> <input type="text" id="val1"> <button id ='bt'>确认</button> <script src="jquery-3.3.1.min.js"></script> <script> $('#bt').click(function () { if($('#z').text() != $('#val1').val()){ alert('验证码输入错误'); }else { alert('太棒了!正确'); } }) </script>

    运用jquery和php两种函数 -------------勿喷本人只是练习数组

    Processed: 0.010, SQL: 8