TP5.0登录验证码实现

<div class="loginbox-textbox">
  <input class="form-control" placeholder="请输入验证码" name="captcha" type="text"/>
  <img id="cap" alt="验证码" title="点击刷新" style="width:220px;cursor: pointer" onclick="this.src='{:captcha_src()}'" src="{:captcha_src()}"/>
</div>

在输入验证码的input框的name值加上captcha  用来验证;

onclick函数是为了点击刷新验证码,等于点击重新加载验证码

对应控制器则添加

//这一步是获取输入的验证码
$captcha = input("param.captcha");
//验证是否正确如果输入错误则进入这个判断
if(!captcha_check($captcha)){
    echo "<script>alert('请输入正确验证码')</script>";
}

修改验证码参数的文件位置:你的根目录开始\vendor\topthink\think-captcha\src\Captcha.php

具体如何修改请自行查看TP手册

猜你喜欢

转载自www.cnblogs.com/lcxin/p/10802166.html