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
$config = [
'session_key' => 'custom_csrf_token', // Optional: Customize session key'token_name' => '_custom_csrf', // Optional: Customize token name'expiration' => 600, // Optional: Customize token expiration time (in seconds)
];
$csrfProtection = newCSRFProtection($config);
// Generate and retrieve CSRF token$token = $csrfProtection->generateToken();
echo"Generated Token: $token\n";
// Get the current CSRF token$currentToken = $csrfProtection->getToken();
echo"Current Token: $currentToken\n";
// Validate a submitted token$submittedToken = $_POST['custom_csrf_token'] ?? '';
if ($csrfProtection->validateToken($submittedToken)) {
echo"Token is valid.\n";
} else {
echo"Token is invalid or expired.\n";
}
// Get the CSRF token as a hidden input field for a form$formTokenField = $csrfProtection->getTokenField();
echo"Form Token Field: $formTokenField\n";
// Get the CSRF token as a meta tag for use in HTML headers$metaTokenTag = $csrfProtection->getTokenMeta();
echo"Meta Token Tag: $metaTokenTag\n";