# csrf()

Checks / returns a CSRF token

****

- Source: <https://github.com/getkirby/kirby/tree/5.5.3/config/helpers.php#L73>

****

```php
csrf(string|null $check = null): string|bool
```

## Parameters

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

## Return types

`string` or `bool`

Either the token or a boolean check result

## Examples

### Token generation

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

### Checking the token

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