用tp实现中文验证码

<?php
namespace Home\Controller;
use Think\Controller;
use Home\Model\loginModel; 
class TestController extends Controller
{
    public function Add ()
    {
        /*$login=D("login");*/
        $login=new loginModel();
        //var_dump($login);
        //var_dump($login->select());
        if(empty($_POST))
        {
            $this->display();
        }
        else
        { 
           $z= $login->create();
          //var_dump ($z);
          
           if($z)
           {
               echo "This Is Ok";
               //$login->add();
           }
           else
           {
               $str=$login->getError();
               $this->assign("error",$str);
               $this->display();
           }
           
        }
        
    }
    public function YZM()
    {
        $config=array(
                                                                                                                     'useImgBg'  =>  true,           // 使用背景图片 
                                                                                                                    'fontSize'  =>  25,              // 验证码字体大小(px)
                                                                                                                    'useCurve'  =>  true,            // 是否画混淆曲线
                                                                                                                    'useNoise'  =>  true,            // 是否添加杂点    
                                                                                                                    'imageH'    =>  0,               // 验证码图片高度
                                                                                                                    'imageW'    =>  0,               // 验证码图片宽度
                                                                                                                    'length'    =>  5,               // 验证码位数
                                                                                                                    
'useZh'     =>    true,
                                                                                                                'fontttf'   =>  'STKAITI.TTF',              // 验证码字体,不设置随机获取
                                                                                                                    'bg'        =>  array(243, 251, 254),  // 背景颜色
                                                                                                                    'reset'     =>  true,           // 验证成功后是否重置

                                                                                                                
                                                                                                                    
        );
        $v=new\Think\Verify($config);
        $v->entry();
    }
    public function Denglu()
    {
        if(empty($_POST))
        {
            $this->display();
        }
        else
        {
            $v=new\Think\Verify();
            $z=$v->check($_POST["YZM"]);
            var_dump($z);
        }
        
    }
}
<!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>
<script src="../../../../../jq.js"></script>//引入路径一定要注意,最好是绝对路径
</head>

<body>
<form action="__SELF__" method="post" >
<div>用户名:<input type="text" name="UserName" /></div>
<div>密码:<input type="text" name="Password" /></div>
<div>验证码:<img id="yzm" src="__CONTROLLER__/YZM" /><input type="text" name="YZM" /></div>
<div><input type="submit" value="登录" /></div>
</form>

</body>
</html>
<script type="text/javascript">

$(document).ready(function(e) {
    

    $("#yzm").click(function(){
        
        var str = "a/"+Math.random();//火狐浏览器不加随机数有缓存
        $(this).attr("src","__CONTROLLER__/YZM/"+str);
         
    }
    
    )
    
});
</script>

 

转载于:https://www.cnblogs.com/crazy-zw/p/5504259.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值