PHPackages                             maer/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. maer/csrf

ActiveLibrary[Security](/categories/security)

maer/csrf
=========

A small CSRF package for PHP

1.1.0(8y ago)53.1k2MITPHPPHP &gt;=5.4.0

Since Oct 16Pushed 8y ago1 watchersCompare

[ Source](https://github.com/magnus-eriksson/csrf)[ Packagist](https://packagist.org/packages/maer/csrf)[ RSS](/packages/maer-csrf/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (6)Used By (2)

A small CSRF package for PHP
============================

[](#a-small-csrf-package-for-php)

Quickly generate and validate tokens to prevent Cross-Site Request Forgery (CSRF) attacks.

> ***Important:** This package only helps you with the CSRF tokens. To truly be safe from CSRF, you also need to protect yourself against [Cross-site scripting (XSS)](https://en.wikipedia.org/wiki/Cross-site_scripting) as well.*

Install
-------

[](#install)

Git clone or use composer to download the package with the following command:

```
composer require maer/csrf 1.*

```

Usage
-----

[](#usage)

Include composers autoloader or include the files in the `src/` folder manually. *(start with `CsrfInterface.php`-file)*

#### Create a new instance

[](#create-a-new-instance)

```
$csrf = new Maer\Security\Csrf\Csrf();

```

***Important:** You can create a new instance when ever in your application, but before you make any calls to it, you need to start the session yourself. This package does not make any assumptions on how you manage your sessions (you might use: session\_start() or you might use Symfonys Session package etc...)*

#### Approach 1: Manually add the hidden field

[](#approach-1-manually-add-the-hidden-field)

```
