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

藏色散人
Release: 2022-01-04 10:01:29
forward
2203 people have browsed it

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()}" />
Copy after login

or

{:token_field()}
Copy after login
# 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) {
            // ...
        }
        
    }
Copy after login

Validator verification

$rule = [
        &#39;name&#39;  =>  &#39;require|max:25|token&#39;,
        &#39;email&#39; =>  &#39;email&#39;,
    ];
Copy after login
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!

Related labels:
source:phpfv.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template