## 使用
在模版內添加驗證碼的顯示代碼
~~~
{{ captcha\_img() }}
~~~
或者
~~~
<img title="點擊刷新" src="{{ captcha_src() }}" onclick="this.src='{{ :captcha_src() }}?'+Math.random();"></img>
~~~
## 后端驗證
手動驗證
~~~
if(!captcha_check($captcha)){
// 驗證失敗
};
~~~
驗證器驗證
~~~
$this->validate($data,[
'captcha|驗證碼'=>'require|captcha'
]);
~~~
## 自定義驗證碼
在控制器中使用下面的代碼進行驗證碼生成:
~~~
<?php
namespace app\index\controller;
use system\core\Captcha;
class Index
{
public function verify()
{
return Captcha::create();
}
}
~~~
然后訪問下面的地址就可以顯示驗證碼:
~~~
http://serverName/index/index/verify
~~~
在模板中就可以使用下面的代碼顯示驗證碼圖片
~~~
<div><img src="{{ url('index/verify') }}" alt="captcha" /></div>
~~~