• tp框架实现验证码验证


    //实现验证页面

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    <script src="__PUBLIC__/js/jquery-1.11.2.min.js"></script>
    <body>
    <form action="__ACTION__" method="post">
    <img src="__CONTROLLER__/yzm" id="img" />
    <input type="text" name="yzm" />
    <input  type="submit" value="注册"/>
    
    </form>
    <script>
    $("#img").click(function(){
        var a = Math.ceil(Math.random()*10);//如果浏览器不兼容可以设置随机数(Math.ceil)是四舍五入化为整数
        $(this).attr("src","__CONTROLLER__/yzm/a/"+a+"");//设点击事件从新设置src属性($(this).attr("src","__CONTROLLER__))如果是兼容性好的(浏览器可以使用)
        //如果兼容不好的不许用生成随机数的方式如($(this).attr("src","__CONTROLLER__/yzm/a/"+a+"");)
        })
    </script>
    </body>
    </html>

    //调方法实现验证<?php

    namespace HomeController;
    use ThinkController;
    class TestController extends Controller 
    {
            
        public function yanzhengma()    
        {    
        
            if(empty($_POST))
            {
            $this->show();    
            }
            else
            {
            $Verify= new ThinkVerify();//掉方法    
            var_dump($Verify->check($_POST["yzm"]));//输出在该验证码的常量如果为true成功 为false失败 
            }
            
        }    
        public function yzm()
        {
        $Verify= new ThinkVerify();    
        $Verify->fontSize=30;//输出验证码的大小
    //$Verify->length=2;//输出验证码的长度:如果=2就有2个随机数(默认是6位数)

    //$Verify->fontttf="5.ttf";//输出为5.ttf的字体 //$Verify->useImgBg=true;//开启验证码背景图片功能 随机使用Thinkphp/Library/Think/Verify/bgs目录下的随机数
    $Verify->useZh=true;//使用中文验证码,可以设置为:true在(Think/Library/Think/Verify/zhttf)的目录下设置中文字体

    $Verify->entry();//生成验证码 } }
  • 相关阅读:
    python中的json
    vmware workstation中的NAT配置
    python内置的一些模块
    datetime
    线程池的工作过程示例
    java io read中申请读的长度与实际长度不同|RocketMQ源码
    RocketMQ集群搭建及安装rocketmq-console
    使用MAT分析JVM内存溢出
    jdbcTemplate小用总结
    Spring线程安全为何非安全,场景重现,解决安全小结
  • 原文地址:https://www.cnblogs.com/liuran123/p/6226617.html
Copyright © 2020-2023  润新知