Skip to content

Kirby 3.9.8

csrf()

Checks / returns a CSRF token

csrf(?string $check = null): string|bool

Parameters

Name Type Default Description
$check string|null null Pass a token here to compare it to the one in the session

Return type

string|bool

Examples

Token generation

<input type="hidden" name="csrf" value="<?= csrf() ?>">

Checking the token

$token = get('csrf');
if(csrf($token) === true) {
  // Success
} else {
  // Token doesn't match
}