使用tp5自带图片验证

前端:
<label>验证码:</label> <input type="text" class="textBox" placeholder="看不清 请点击图片更换"
                               name="code" id="yzm" placeholder="验证码" />
    <img src="{:captcha_src()}" alt=""  class="passcode" style="height:43px;cursor:pointer;width: 130px;height: 40px;margin-left: 75px;" onclick="this.src=this.src+'?'"> 

后端代码:

controller:

//接收输入的验证码
$info = $this->request->param();
//验证验证码是否输入正确
$va=$this->validate($info,'validate名');
if($va !== true){/如果不正确,则返回错误信息
   $this->error($va);
}

validate:

protected $rule=[//require 存在   captcha 验证码  
    'code'=>'require|captcha'
];

猜你喜欢

转载自blog.csdn.net/hai__yin/article/details/81197442
今日推荐