發(fā)表日期:2018-12 文章編輯:小燈 瀏覽次數(shù):3480
驗(yàn)證規(guī)則支持對(duì)表單的令牌驗(yàn)證,首先需要在你的表單里面增加下面隱藏域:
<input type="hidden" name="__token__" value="{$Request.token}" />
或者
{:token()}
然后在你的驗(yàn)證規(guī)則中,添加token
驗(yàn)證規(guī)則即可,例如,如果使用的是驗(yàn)證器的話,可以改為:
protected $rule = ['name'=>'require|max:25|token','email' =>'email',];
如果你的令牌名稱(chēng)不是__token__
,則表單需要改為:
<input type="hidden" name="__hash__" value="{$Request.token.__hash__}" />
或者:
{:token('__hash__')}
驗(yàn)證器中需要改為:
protected $rule = ['name'=>'require|max:25|token:__hash__','email' =>'email',];
如果需要自定義令牌生成規(guī)則,可以調(diào)用Request
類(lèi)的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}" />
或者不需要在控制器寫(xiě)任何代碼,直接在模板中使用:
{:token('__token__', 'sha1')}
日期:2018-12 瀏覽次數(shù):4980
日期:2018-12 瀏覽次數(shù):5264
日期:2018-12 瀏覽次數(shù):4343
日期:2018-12 瀏覽次數(shù):3695
日期:2018-12 瀏覽次數(shù):4102
日期:2018-12 瀏覽次數(shù):3661
日期:2018-12 瀏覽次數(shù):3702
日期:2018-12 瀏覽次數(shù):6521
日期:2018-12 瀏覽次數(shù):3476
日期:2018-12 瀏覽次數(shù):3578
日期:2018-12 瀏覽次數(shù):3706
日期:2018-12 瀏覽次數(shù):4829
日期:2018-12 瀏覽次數(shù):3214
日期:2018-12 瀏覽次數(shù):3530
日期:2018-12 瀏覽次數(shù):3332
日期:2018-12 瀏覽次數(shù):3214
日期:2018-12 瀏覽次數(shù):3587
日期:2018-12 瀏覽次數(shù):3453
日期:2018-12 瀏覽次數(shù):4553
日期:2018-12 瀏覽次數(shù):4001
日期:2018-12 瀏覽次數(shù):3515
日期:2018-12 瀏覽次數(shù):4317
日期:2018-12 瀏覽次數(shù):3299
日期:2018-12 瀏覽次數(shù):3290
日期:2018-12 瀏覽次數(shù):3246
日期:2018-12 瀏覽次數(shù):3407
日期:2018-12 瀏覽次數(shù):3691
日期:2018-12 瀏覽次數(shù):3479
日期:2018-12 瀏覽次數(shù):3411
日期:2018-12 瀏覽次數(shù):3466
Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.