Search code examples
phpajaxcodeigniter-3csrf-protectionion-auth

Error_csrf in edit user form when call Ajax function in ion_auth


I have error_csrf in edit user form when call function Ajax drop down for Country State & City. I have the same error with:

$config['csrf_protection'] = FALSE;

And

$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array('dashboard/get_city/.*+','dashboard/get_city/[0-9]+');

When i submit the form of edit user i have this error "This form post did not pass our security checks." but only when i change drop-down of country who it call an Ajax function {dashboard/get_city/[0-9]+} to update a drop-down of list of city, and when i don't change de drop-down of country and they are not a call to this Ajax function, the submit form is OK, and the user information are update

Thank you for your help.


Solution

  • That is csrf protection by ion auth, you just remove the line like this :

    // do we have a valid request?
    if ($this->_valid_csrf_nonce() === FALSE)
    {
        show_error($this->lang->line('error_csrf'));
    }
    

    And just leave built-in Codeigniter CSRF protection to true :

    $config['csrf_protection'] = TRUE;