search
HomePHP FrameworkThinkPHPHow to use form token to verify the validity of data source in ThinkPHP6

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. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor