PHP code example of volnix / csrf

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

    

volnix / csrf example snippets


	


<form action="index.php" method="post">
	<input type="hidden" name="<?= \Volnix\CSRF\CSRF::TOKEN_NAME 


<form action="index.php" method="post">
	<?= \Volnix\CSRF\CSRF::getHiddenInputString() 


<form action="index.php?<?= \Volnix\CSRF\CSRF::getQueryString() 


<form action="index.php" method="post">
	<?= \Volnix\CSRF\CSRF::getHiddenInputString('custom_token_name') 


// generic POST data
if ( CSRF::validate($_POST) ) {
	// good token
} else {
	// bad token
}



// symfony object
$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();

if ( CSRF::validate($request->request->all()) ) {
	// good token
} else {
	// bad token
}



// validating with a custom token name
if ( CSRF::validate($_POST, 'my_custom_name') ) {
	// good token
} else {
	// bad token
}