You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for creating this library! Below I shared a quick example of how to use it.
Save the code below as a PHP file, put it on your webserver and run it.
Before running:<br>
1.Open a terminal and navigate to your webserver root directory.<br>
2.Download the library with: "composer require paragonie/anti-csrf".<br>
The package is now installed in the vendor/ folder.<br><br>
<?php//Don't forget to call this:session_start();
//Because of $_SERVER['DOCUMENT_ROOT'], you can place this PHP-file anywhere on the webserver.require$_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
useParagonIE\ConstantTime\{
Base64UrlSafe,
Binary
};
useParagonIE\AntiCSRF\AntiCSRF;
?>
<form method="POST">
<?php//Generate CSRF token$server = $_SERVER;
$csrft = newAntiCSRF( $server);
$token_html = $csrft->insertToken('', true);
?>
<input type="submit">
</form><br>
<?php//Check CSRF token$csrf = new \ParagonIE\AntiCSRF\AntiCSRF;
if (!empty($_POST)) {
if ($csrf->validateRequest()) {
echo'Valid form';
} else {
// Log a CSRF attack attemptecho'Token is invalid';
}
}
?>
The reason I share this, is because it took me a while to understand how to use the library. So I hope this helped others.
Also, if you are reading this and didn't really use composer before, like me, This tutorial should help you out.
The text was updated successfully, but these errors were encountered:
Thanks for creating this library! Below I shared a quick example of how to use it.
Save the code below as a PHP file, put it on your webserver and run it.
The reason I share this, is because it took me a while to understand how to use the library. So I hope this helped others.
Also, if you are reading this and didn't really use
composer
before, like me, This tutorial should help you out.The text was updated successfully, but these errors were encountered: