codeigniter csrf错误提交表单 [英] codeigniter csrf error on form submission

查看:187
本文介绍了codeigniter csrf错误提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用codeigniter括号的表单

  echo form_open('signup'); 

echo form_close();

当我提交它时,我得到以下错误

 遇到错误

不允许您请求的操作。

总是但通常...

 

即使隐藏的输入字段存在, code>< div style =display:none>
< input type =hiddenvalue =令牌名称在这里name =csrf_token_name>
< / div>

这种情况也发生在类似的表单上(登入)



EDIT:通过表单生成的HTML

 < form accept-charset =utf -8method =postaction =http://www.example.com/signup> 
< div style =display:none>
< input type =hiddenvalue =93565fb5855d31af3d46bd655b11a4a6name =csrf_token_name>
< / div>
< input id =usernametype =textplaceholder =Usernamemaxlength =20value =name =username>
< input id =emailtype =textplaceholder =Emailvalue =name =email>
< input id =passwordtype =passwordplaceholder =Passwordvalue =name =password>
< input id =submittype =submitvalue =注册name =submit>
< / form>


解决方案

b
$ b

尝试此

 < input type =hiddenname =< ;? php echo $ this-> security-> get_csrf_token_name();?> value =<?php echo $ this-> security-> get_csrf_hash();?> /> 

值必须是codeigniter为csrf令牌计算的值。



或使用form helper和codeigniter将自动添加此隐藏字段。


I have a form using codeigniter brackets

echo form_open('signup');

echo form_close();

and when i submit it i get the following error

An Error Was Encountered

The action you have requested is not allowed.

NOT always but often...

even when the hidden inputfield exist inside the form:

<div style="display:none">
<input type="hidden" value="token name is here" name="csrf_token_name">
</div>

this also happens on a similar form(signin)

EDIT: html generated via form

<form accept-charset="utf-8" method="post" action="http://www.example.com/signup">
<div style="display:none">
<input type="hidden" value="93565fb5855d31af3d46bd655b11a4a6" name="csrf_token_name">
</div>
<input id="username" type="text" placeholder="Username" maxlength="20" value="" name="username">
<input id="email" type="text" placeholder="Email" value="" name="email">
<input id="password" type="password" placeholder="Password" value="" name="password">
<input id="submit" type="submit" value="Sign up" name="submit">
</form>

解决方案

you are doing it wrong.

try this

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

the value must be what codeigniter calculates for the csrf token.

or use form helper and codeigniter will add this hidden field automatically.

这篇关于codeigniter csrf错误提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆