PHP code example of publishing-kit / csrf

1. Go to this page and download the library: Download publishing-kit/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/ */

    

publishing-kit / csrf example snippets

 php
$session = new Laminas\Session\Container();
$storage = new PublishingKit\Csrf\LaminasSessionTokenStorage($session);
$reader = new PublishingKit\Csrf\StoredTokenReader($storage);
$token = $reader->read('foo');
$validator = new PublishingKit\Csrf\StoredTokenValidator($storage);
$validator->validate('foo', $token);
 php
$session = new Symfony\Component\HttpFoundation\Session\Session(
    new Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage()
);
$storage = new PublishingKit\Csrf\SymfonySessionTokenStorage($session);
$reader = new PublishingKit\Csrf\StoredTokenReader($storage);
$token = $reader->read('foo');
$validator = new PublishingKit\Csrf\StoredTokenValidator($storage);
$validator->validate('foo', $token);