CodeIgniter Error: “The action you have requested

2019-08-05 09:55发布

问题:

In my application I have a contact us form in http://www.example.com. If i am sending from www.example.com in the url then the form is submitted. If I send the form from example.com in the url the form is giving me a Error: "The action you have requested is not allowed."

I think the problem is because i enabled csrf protection in codeigniter config file.When i make it false it is working good.How can i resolve this issue when the csrf protection is enabled.

Thanks in Advance!

回答1:

Just place this line of code in your form to solve this.

<input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">


回答2:

Try this in your form:

<input type="hidden" name="csrf_hash_name" value="your-hash-value-here">