PHP code example of madeorsk / nocsrf

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

    

madeorsk / nocsrf example snippets



use NoCSRF\NoCSRF;

// Creating a new NoCSRF instance, which manages anti-CSRF tokens.
$nocsrf = new NoCSRF();

// Get an anti-CSRF token (to add in a hidden input field or a request header).
$token = $nocsrf->getToken();

// Verify anti-CSRF token.
if ($nocsrf->verify($token))
	echo "Anti-CSRF token is VALID!";
else
	echo "Anti-CSRF token is INVALID.";


$nocsrf = new NoCSRF([
	"keyGenerator" => new OpensslKeyGenerator(16),
	"keyStorage" => new SessionKeyStorage(),
	"tokenManager" => new HMACTokenManager(),
]);