TP 验证码

TP自带验证码类Verify.class.php

生成验证码

public function verify_c(){
        session_start();
        ob_clean();
        $Verify = new ThinkVerify();  
        $Verify->codeSet = '0123456789';
        $Verify->expire = 60;  
        $Verify->entry();  
    }

页面调用

<input name="verify" placeholder="验证码" type="text">                  
    <img onclick="this.src=this.src+'?'+Math.random()" src="{:U('tool/verify_c')}" title="点击刷新">

验证码验证

function check_verify($code, $id = ''){
    $verify = new ThinkVerify();
    return $verify->check($code, $id);
}

主要就是上面的散步,但是有几个注意点

1 tp的验证码是加密后保存在Session中的, 所以.在生成验证码前要开启session(session_start), 否则的话检验验证码的时候一直提示验证码错误

2 tp生成验证码有时, 图片显示不出来, 需要使用ob_clean();清除缓存

PS: 有些需要看源码才能发现问题的

原文地址:https://www.cnblogs.com/yyf573462811/p/6387361.html