Google News
logo
CodeIgniter - Interview Questions
What is CSRF token in CodeIgniter? How to set CSRF token?
* CSRF(Cross-Site Request Forgery) token is a randomly generated value that gets modified with every HTTP request sent by webform.

* A CSRF attack forces a browser of the logged-on victim for sending a forged HTTP request, including the session cookie of the victim and other information related to authorization, to a web application. A CSRF token is used for setting or activating the protection in CodeIgniter.

* CSRF token is saved in the user’s session when it is added in the website form. When we submit the form, the website compares both submitted tokens and saved tokens in the session. If they are the same, a request is considered valid. When the page gets loaded token value will also be changed each time. Thus it becomes difficult for the hackers to identify the current token.

* To set CSRF, you have to set the corresponding config value as true in your application/config/config.php file.
Syntax : $config['csrf_protection'] = TRUE;

* If you use the form helper, the form_open() method will automatically insert a hidden CSRF field in your forms.
Advertisement