zoukankan      html  css  js  c++  java
  • Thinkphp 3.2 添加 验证码 如何添加。

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

    <?php
    namespace HomeController;
    use ThinkController;
    class BookController extends Controller {
    
        public function verify_c(){
            $Verify = new ThinkVerify();
            $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

  • 相关阅读:
    python学习之控制流1
    python学习之字符串转换
    python学习之数据类型与运算符号
    python之获取微信好友列表并保存文档中
    python之微信自动发送消息
    python之微信好友统计信息
    java并发编程--AtomicInteger
    java.time学习
    chrome插件
    classpath和classpath*
  • 原文地址:https://www.cnblogs.com/xiaoxiao2014/p/4138000.html
Copyright © 2011-2022 走看看