这个 codeigniter 活动记录查询安全吗?
我仅在我的 ci 网站的管理端使用此代码,此数据库插入安全吗?
function addCategory(){
$data = array(
'name'=> $_POST['name'],
'shortdesc'=>$_POST['shortdesc'],
'longdesc' => $_POST['longdesc'],
'status'=>$_POST['status'],
'parentid' => $_POST['parentid']
);
$this->db->insert('categories', $data);
}
I am using this code for admin side only for my ci site, is this db insert safe ?
function addCategory(){
$data = array(
'name'=> $_POST['name'],
'shortdesc'=>$_POST['shortdesc'],
'longdesc' => $_POST['longdesc'],
'status'=>$_POST['status'],
'parentid' => $_POST['parentid']
);
$this->db->insert('categories', $data);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Code Igniter 会为您正确转义这些值。话虽如此,您应该使用输入类来获取发布数据;如果您在配置文件中这样设置,它不仅可以自动保护 XSS,而且如果这些值中的任何一个未设置,您都不会收到警告:
您还可以将函数调用直接放入数组中:
或者如果您想在 POST 值不存在时设置默认值:
Code Igniter will properly escape those values for you. That being said, you should use the input class to get your post data; not only can it automatically protect vs XSS if you've set it that way in your config file, if any of those values are unset you won't get warnings spewing out:
You can also put the function call directly in your array:
Or if you want to set default values when the POST value is not there:
我建议以这种方式解决这个问题
,这样,如果您指定的任何静态值未设置,它们就不会作为
false
添加到数据插入中(什么$this->; input->post()
如果未设置则返回)I would recommend tackling it this way
This way if any of those static values you specified are not set, they don't get added to the data insert as
false
(what$this->input->post()
returns if they are not set)