一、生成验证码
1、commonController.class.php
class CommonController extends Controller{
public function getVerify(){
$Verify = new ThinkVerify();
$Verify->entry();
}
public function validatVerify(){
二、验证码检测
$verify = new ThinkVerify();
return $verify->check($code, $id); //$id是多个验证的情况下写的,一个不需要
}
}
三、地址输入就能看了
四、视图
<img src="{:U("Common/get....")}" onclick='src={:U("Common/get....")}' style="cursor=pointer"/>
indexcontroller.class.php //用于验证的
public function showSession(){
dump($_SESSION);
$verify = new ThinkVerify();
return $verify->check($code, $id);
}
===========
控制器-》前置验证 _before_insert(){}
=========================以下自己写的
====================================
start
一、在里面写前置方法LoginController.class.php (验证传过来的值是否正确)
public function _before_login(){
$verify = new ThinkVerify();
if(!$verify->check(I("post.verify_code"))){
//$this->redirect("login");
$this->error("提交失败");
//exit();
}
}
二、可以单独建立一个获取验证码的控制器
VerifyController.class.php
<?php
namespace AdminController;
header('Content-type:text/html;charset=utf-8');
use ThinkController;
class VerifyController extends Controller {
public function getVerify(){
$Verify = new ThinkVerify();
$Verify->fontSize = 50;
$Verify->length = 4;
//$Verify->useImgBg = true;
$Verify->useNoise = false;
$Verify->bg = [255, 255, 128];
$Verify->entry();
}
}
三、在视图html页面
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-reddit"></i></span>
<input type="text" class="form-control" placeholder="verify code" name="verify_code" style="130px">
//在方法中获取验证码
<img src="{:U('Verify/getVerify')}" style="110px;height:40px;cursor: pointer;" onclick="src='{:U('Verify/getVerify')}'"/>
</div>