codeigniter CSRF error: “The action you have requested is not allowed.”

后端 未结 14 2324
长发绾君心
长发绾君心 2020-11-28 12:57

I enabled the csrf_protection option in codeigniter\'s config file, and used form_open() function to create my forms. But when I submit the form, this error occurs:

相关标签:
14条回答
  • 2020-11-28 13:11

    if you allow true in $config['csrf_protection'] = true; within config file and you are also add autoload form than we can use.

    Step 1. within config folder autoload file upload form helper

    $autoload['helper'] = array('url', 'file','form');
    

    Step 2.

    $config['csrf_protection'] = true; 
    

    Step 3. while uploading in view folder

    <?php echo form_open_multipart('admin/file_upload'); ?>
    

    Otherwise, you can use only

    $config['csrf_protection'] = false;
    
    0 讨论(0)
  • 2020-11-28 13:17

    In the config if you have set the cookie domain name

    $config['cookie_domain']    = 'xyz.com';
    

    and you browse using localhost. you will get the error

    The action you have requested is not allowed

    check that if helps

    0 讨论(0)
  • 2020-11-28 13:17

    I got this error white creating a csv_upload form . just put this code in your form.

    <input type="hidden" 
                   name="<?php echo $this->security->get_csrf_token_name();?>" 
                   value="<?php echo $this->security->get_csrf_hash();?>">
    
    0 讨论(0)
  • 2020-11-28 13:19

    Just Include this in your form and everything will be fine then.

    <input type="hidden" name="<?php echo $this->security->get_csrf_token_name();?>" value="<?php echo $this->security->get_csrf_hash();?>">
    
    0 讨论(0)
  • 2020-11-28 13:20

    The easiest one for me was to whitelist the URI as explained in CodeIgniter User Guide (here)

    Select URIs can be whitelisted from csrf protection (for example API endpoints expecting externally POSTed content). You can add these URIs by editing the ‘csrf_exclude_uris’ config parameter:

    $config['csrf_exclude_uris'] = array('api/person/add');
    
    0 讨论(0)
  • 2020-11-28 13:20

    When all else failed, I noticed that I had my cookie variables set, removing cookie name, etc. resolved my issue.

    0 讨论(0)
提交回复
热议问题