码迷,mamicode.com
首页 > Web开发 > 详细

Thinkphp 3.2 添加 验证码 如何添加。

时间:2014-12-02 19:00:25      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   ar   color   sp   java   

1,在home模块indexController.class.php中,加入以下代码

<?php
namespace Home\Controller;
use Think\Controller;
class BookController extends Controller {

    public function verify_c(){
        $Verify = new \Think\Verify();
        $Verify->fontSize = 18;
        $Verify->length   = 4;
        $Verify->useNoise = false;
        $Verify->codeSet = ‘0123456789‘;
        $Verify->imageW = 130;
        $Verify->imageH = 50;
        //$Verify->expire = 600;
        $Verify->entry();
    }
  
   
    public function img(){
       $this->display();
    }

}

 

2. 在img 视图中,加入以下代码

<script type="text/javascript" src="__PUBLIC__/js/jquery2.0.3.min.js"></script>
<p class="top15 captcha" id="captcha-container">
    <input name="verify" width="50%" height="50" class="captcha-text" placeholder="验证码" type="text">
    <img width="100" class="left15" height="50" alt="验证码" src="{:U(‘Home/Book/verify_c‘,array())}" title="点击刷新">
</p>
        <script type="text/javascript">
            $(function(){
                var captcha_img = $(#captcha-container).find(img);
                var verifyimg = captcha_img.attr("src");
                captcha_img.attr(title, 点击刷新);
                captcha_img.click(function(){
                    if( verifyimg.indexOf(?)>0){
                        $(this).attr("src", verifyimg+&random=+Math.random());
                    }else{
                        $(this).attr("src", verifyimg.replace(/\?.*$/,‘‘)+?+Math.random());
                    }
                });
            })
        </script>

这样就可以了,就能显示出 验证码了。

参考学习 网址:http://blog.csdn.net/yafei450225664/article/details/40424025

Thinkphp 3.2 添加 验证码 如何添加。

标签:des   style   blog   http   io   ar   color   sp   java   

原文地址:http://www.cnblogs.com/xiaoxiao2014/p/4138000.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!