Csrf Package provides Cross Site Request Forgery protection by comparing provided token with session token to ensure request validity.

Installation

With Composer

composer require glowy/csrf

Usage

use Glowy\Csrf\Csrf;

// Start PHP session
session_start();

/**
 * Create the csrf object.
 *
 * @param string  $tokenNamePrefix  Prefix for CSRF token name.
 * @param string  $tokenValuePrefix Prefix for CSRF token value.
 * @param int     $strength         Strength.
 *
 * @throws CsrfException
 */
$csrf = new Csrf('__csrf_name',
                 '__csrf_value',
                 32);

Methods

getTokenName Get token name.
getTokenValue Get token value.
isValid Checks whether an incoming CSRF token name and value is valid.