PHP code example of gokhankurtulus / csrf

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

    

gokhankurtulus / csrf example snippets




use Csrf\Csrf;

$token = Csrf::newToken('my_token', 1200); // Generate a token named 'my_token' that expires in 20 minutes

$token = Csrf::getToken('my_token'); // Get the token object for 'my_token'

$input = Csrf::createInput('my_token', 1800); // Generate an HTML input field for 'my_token' that expires in 30 minutes
echo $input; // Output the HTML input field

$isVerified = Csrf::verify('my_token', true); // Verify the submitted token for 'my_token' and unset it if verified
if ($isVerified) {
    // Token is valid
} else {
    // Token is invalid
}

Csrf::unsetToken('my_token'); // Unset the token named 'my_token'

$isSessionStarted = Csrf::isSessionStarted(); 

// Check if a session is started
if ($isSessionStarted) {
    // Session is active
} else {
    // Session is not active
}