發表日期:2018-12 文章編輯:小燈 瀏覽次數:3477
驗證規則支持對表單的令牌驗證,首先需要在你的表單里面增加下面隱藏域:
<input type="hidden" name="__token__" value="{$Request.token}" />
或者
{:token()}
然后在你的驗證規則中,添加token
驗證規則即可,例如,如果使用的是驗證器的話,可以改為:
protected $rule = ['name'=>'require|max:25|token','email' =>'email',];
如果你的令牌名稱不是__token__
,則表單需要改為:
<input type="hidden" name="__hash__" value="{$Request.token.__hash__}" />
或者:
{:token('__hash__')}
驗證器中需要改為:
protected $rule = ['name'=>'require|max:25|token:__hash__','email' =>'email',];
如果需要自定義令牌生成規則,可以調用Request
類的token
方法,例如:
namespace app\index\controller;use think\Controller;class Index extends Controller{public function index(){$token = $this->request->token('__token__', 'sha1');$this->assign('token', $token);return $this->fetch();}}
然后在模板表單中使用:
<input type="hidden" name="__token__" value="{$token}" />
或者不需要在控制器寫任何代碼,直接在模板中使用:
{:token('__token__', 'sha1')}
日期:2018-12 瀏覽次數:4977
日期:2018-12 瀏覽次數:5260
日期:2018-12 瀏覽次數:4340
日期:2018-12 瀏覽次數:3692
日期:2018-12 瀏覽次數:4093
日期:2018-12 瀏覽次數:3657
日期:2018-12 瀏覽次數:3700
日期:2018-12 瀏覽次數:6517
日期:2018-12 瀏覽次數:3471
日期:2018-12 瀏覽次數:3576
日期:2018-12 瀏覽次數:3702
日期:2018-12 瀏覽次數:4827
日期:2018-12 瀏覽次數:3212
日期:2018-12 瀏覽次數:3528
日期:2018-12 瀏覽次數:3330
日期:2018-12 瀏覽次數:3211
日期:2018-12 瀏覽次數:3584
日期:2018-12 瀏覽次數:3451
日期:2018-12 瀏覽次數:4549
日期:2018-12 瀏覽次數:3999
日期:2018-12 瀏覽次數:3511
日期:2018-12 瀏覽次數:4312
日期:2018-12 瀏覽次數:3294
日期:2018-12 瀏覽次數:3287
日期:2018-12 瀏覽次數:3242
日期:2018-12 瀏覽次數:3404
日期:2018-12 瀏覽次數:3687
日期:2018-12 瀏覽次數:3476
日期:2018-12 瀏覽次數:3408
日期:2018-12 瀏覽次數:3462
Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.