Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Drupal.php

function Drupal::csrfToken

Returns the CSRF token manager service.

The generated token is based on the session ID of the current user. Normally, anonymous users do not have a session, so the generated token will be different on every page request. To generate a token for users without a session, manually start a session prior to calling this function.

Return value

\Drupal\Core\Access\CsrfTokenGenerator The CSRF token manager.

See also

\Drupal\Core\Session\SessionManager::start()

File

core/lib/Drupal.php, line 622

Class

Drupal
Static Service Container wrapper.

Code

public static function csrfToken() {
    return static::getContainer()->get('csrf_token');
}
RSS feed
Powered by Drupal