如何限制用户编辑 URL 参数
我正在使用 CodeIgniter。当用户编辑 URL 参数时,我收到数据库错误。
我该如何解决这个问题?在 CodeIgniter 中,我在 URL 中传递值 32
http://xyz.com/esebd2/user/link/link_detail/32
如果用户如下所示编辑此值,
http://xyz.com/esebd2/user/link/link_detail/323434
我会收到数据库错误。该怎么办?
function link_detail()
{
$this->common_head();
$lid = $this->uri->segment(4);
$link_data['link_detail'] = $this->linklist->get_detail_link($lid);
//above line to retrive value from database
$this->load->view('user/detaillink_view', $link_data);
$this->common_footer();
}
I am using CodeIgniter. When a user edits the URL parameter, I get a database error.
How can I solve this? In CodeIgniter, I am passing the value 32 in the URL
http://xyz.com/esebd2/user/link/link_detail/32
If the user edits this as shown below,
http://xyz.com/esebd2/user/link/link_detail/323434
I get a database error. What to do?
function link_detail()
{
$this->common_head();
$lid = $this->uri->segment(4);
$link_data['link_detail'] = $this->linklist->get_detail_link($lid);
//above line to retrive value from database
$this->load->view('user/detaillink_view', $link_data);
$this->common_footer();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法阻止用户编辑 URL。如果他/她未经授权,您只能阻止他/她访问该资源。
至于错误消息:任何用户输入都应被视为不可信,并且在使用前应始终进行验证。即使您不希望普通用户更改它。
并且如果出现错误,不输出系统的错误信息。这些仅适用于开发人员,不适用于用户,因为它们可能包含敏感信息。
You cannot prevent the user from editing the URL. You can only prevent that he/she has access to the resource if he/she is not authorized.
And as for the error message: Any user input should be considered as untrustworthy and should always be validated before use. Even if you don’t expect the regular user to change it.
And if an error occurs, don’t output the system’s error message. These are only intended for the developer but not the the user as they can contain sensitive information.
你不知道。而且您也不能限制在客户端通过 POST 表单传递的值。
检查必须在服务器端完成,并且必须能够处理所有可能的值。
You don't. And you can't restrict values passed on POST forms on client side too.
Checks must be done server side, and have to be able to deal with all possible values.