PHPackages                             elhardoum/nonce-php - 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. elhardoum/nonce-php

ActiveLibrary[Security](/categories/security)

elhardoum/nonce-php
===================

Fast PHP nonce and CSRF tokens tool

0.12(7y ago)2214.9k7[2 issues](https://github.com/elhardoum/nonce-php/issues)GPL-3.0PHPPHP &gt;=5.4

Since Oct 30Pushed 3y ago2 watchersCompare

[ Source](https://github.com/elhardoum/nonce-php)[ Packagist](https://packagist.org/packages/elhardoum/nonce-php)[ RSS](/packages/elhardoum-nonce-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (7)Used By (0)

Nonce PHP
=========

[](#nonce-php)

Fast PHP nonce and CSRF tokens tool, add tokens to your web forms and validate nonces easily using browser cookies or a cache driver (or anything else).

[![Build Status](https://camo.githubusercontent.com/d776c94868be72f1967cce3f52106156e0ea5a859d03833fa33e98df36448f3b/68747470733a2f2f7472617669732d63692e6f72672f656c686172646f756d2f6e6f6e63652d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/elhardoum/nonce-php)

Install
-------

[](#install)

Using [composer](https://getcomposer.org):

```
composer require elhardoum/nonce-php
```

Basic Usage
-----------

[](#basic-usage)

First, import and initialize the nonce utility class:

```
// nonce configuration class
$nonceConfig = new \Nonce\Config\Config;

// nonce hash storage, use browser cookies
$nonceStore = new \Nonce\HashStore\Cookie;

// initialize nonce class
$nonceUtil = new \Nonce\Nonce( $nonceConfig, $nonceStore );
```

Then, to create a nonce based on an action name:

```
// make sure you make this call before starting the output or sending HTTP headers
$nonce = $nonceUtil->create( 'signup-form' );
```

Here you see we used the `signup-form` as an action name and we can use that later to verify the nonce supplied to the user request:

Let's use this in our HTML form:

```

    ....
    ....
