English spoken conference

Symfony 5: The Fast Track

A new book to learn about developing modern Symfony 5 applications.

Support this project

WARNING: You are browsing the documentation for Symfony 3.1 which is not maintained anymore. Consider upgrading your projects to Symfony 5.0.

How to Manually Validate a CSRF Token in a Controller

3.1 version
Maintained Unmaintained

How to Manually Validate a CSRF Token in a ControllerΒΆ

Sometimes, you want to use CSRF protection in an action where you do not want to use the Symfony Form component. If, for example, you are implementing a DELETE action, you can use the isCsrfTokenValid() method to check the validity of a CSRF token:

public function deleteAction()
    if ($this->isCsrfTokenValid('token_id', $submittedToken)) {
        // ... do something, like deleting an object

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.