Final Class Yiisoft\Csrf\Synchronizer\SynchronizerCsrfToken
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Stateful CSRF token that is a unique random string. It is stored it in persistent storage available only for the currently logged in user. The same token is added to forms. When the form is submitted, token that came from the form is compared against the token stored.
The algorithm is also known as "Synchronizer Token".
Do not forget to decorate the token with {@see \
Public Methods
Method Details
public function __construct(
CsrfTokenGeneratorInterface $generator,
CsrfTokenStorageInterface $storage
) {
$this->generator = $generator;
$this->storage = $storage;
}
| public string getValue ( ) |
public function getValue(): string
{
$token = $this->storage->get();
if (empty($token)) {
$token = $this->generator->generate();
$this->storage->set($token);
}
return $token;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.