PHP code example of webiik / csrf

1. Go to this page and download the library: Download webiik/csrf library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webiik / csrf example snippets


$csrf = new \Webiik\Csrf\Csrf($token, $session);
$token = $csrf->create();

// Now send the $token to the next request, e.g. using $_POST...

$csrf = new \Webiik\Csrf\Csrf($token, $session);
if ($csrf->validate($_POST[$csrf->getName()])) {
    // CSRF token is valid
}

setName(string $name): void

$csrf->setName('my-csrf-token');

setMax(int $max): void

$csrf->setMax(5);

create(bool $safe = false): string

$csrfToken = $csrf->create();

validate(string $token, bool $safe): bool

$csrf->validate($token);