PHPackages                             ajiho/think-csrf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. ajiho/think-csrf

ActiveLibrary[Security](/categories/security)

ajiho/think-csrf
================

Thinkphp6 solves CSRF attacks

V1.0.0(3y ago)023MITPHP

Since Aug 16Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ajiho/think-csrf)[ Packagist](https://packagist.org/packages/ajiho/think-csrf)[ Docs](https://gitee.com/ajiho/think-csrf)[ RSS](/packages/ajiho-think-csrf/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

think-csrf
==========

[](#think-csrf)

是基于thinkphp6.x封装的一个防止csrf攻击的composer包

为什么还要封装think-csrf
-----------------

[](#为什么还要封装think-csrf)

thinkphp官方的表单令牌其实从实际开发角度来说，它只适合用来防止表单重复提交(虽然官方文档上说可以防止csrf攻击)。 因为框架在验证表单令牌通过后会立马删除session中的token,这样对于ajax提交的方式是非常不友好的， 因为页面没有刷新而session中的表单令牌已经更新导致再次提交表单会失败, 该依赖包就是用来解决这个问题,且验证csrf的token值是长时间保存在cookie中的, 相对于官方表单令牌保存在session中有不会过期、和减轻服务端压力的特点。

防止表单重复提交和防止csrf攻击应该分开来做，你在使用`think-csrf`的同时也不影响你使用tp官方的表单令牌,它 们不会产生冲突

安装
==

[](#安装)

```
composer require ajiho/think-csrf

```

配置
==

[](#配置)

/config/csrf.php

```
