**TP6 圖形驗證碼**
```
安裝:
composer require topthink/think-captcha
生成驗證碼:
namespace app\admin\controller;
use app\BaseController;
use think\captcha\facade\Captcha;
class Login extends BaseController
public function verify()
{
ob_clean();//清除緩存,記得加上
return Captcha::create();
}
}
html頁面使用:
<img src="{:url('login/verify')}" id="LAY-user-get-vercode">
點擊切換驗證碼(js文件):
$("#LAY-user-get-vercode").click(function () {
var src = "/login/verify";
$(this).attr('src', src + "?" + Math.round(Math.random() * 1000));
});
注意事項:
* 驗證碼庫需要開啟Session才能生效:middleware.php中開啟 \think\middleware\SessionInit::class
* ob_clean();//清除緩存,記得加上
```