Home >PHP Framework >ThinkPHP >How to use form token to verify the validity of data source in ThinkPHP6

How to use form token to verify the validity of data source in ThinkPHP6

藏色散人
藏色散人forward
2021-12-10 14:38:202205browse

The following thinkphp framework tutorial column will introduce to you how ThinkPHP6 uses form tokens to verify the validity of data sources. I hope it will be helpful to friends in need!

Use form tokens in thinkphp6 to verify data source validity to prevent attacks:

Use

<input type="hidden" name="__token__" value="{:token()}" />

or

{:token_field()}
# in the template ##The above content will be automatically generated.

Controller verification

    public function index(Request $request)
    {
        $check = $request->checkToken(&#39;__token__&#39;);
        
        if(false === $check) {
            // ...
        }
        
    }

Validator verification

$rule = [
        &#39;name&#39;  =>  &#39;require|max:25|token&#39;,
        &#39;email&#39; =>  &#39;email&#39;,
    ];

Recommended: "

The latest 10 thinkphp video tutorials"

The above is the detailed content of How to use form token to verify the validity of data source in ThinkPHP6. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:phpfv.com. If there is any infringement, please contact admin@php.cn delete