**TP5開發過程中注冊碼類的使用**
# 步驟 #
### 1.引入captcha 類 ##
在控制定義時,引入captcha類;
` use think\Captcha; `
### 2.在生成captcha類時,清空緩存 ##
` ob_end_clean();`
### 3.生成captcha實例,并引入配置文件
` $verify= new Captcha(config('verify'));`
### 4.生成驗證碼圖片,并配置id
` return $verify->entry('reg');`
~~~
//驗證碼
public function verify()
{
if (session('hid')) {
$this->redirect(__ROOT__."/");
}
ob_end_clean();
$verify = new Captcha (config('verify'));
return $verify->entry('reg');
}
~~~
### 5.在網頁中進行引用
~~~
<div class="row">
<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5">
<input type="text" class="form-control" placeholder="" id="verify" style="height:40px;" name="verify" required>
</div>
<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7">
<img class="verify_img" id="verify_img" src="{:url('home/Register/verify')}" onClick="this.src='{:url('home/Register/verify')}'+'?'+Math.random()" style="cursor: pointer;width:100%;border: 1px solid #d5d5d5;height:40px;" title="點擊獲取">
</div>
</div>
~~~
### 6.在控制中進行驗證
$verify_obj =new Captcha ();
if (!$verify_obj->check($verify, 'reg')) {
$this->error(lang('verifiy incorrect'));
}