douhuiqi3855 2015-12-21 22:17
浏览 71
已采纳

使用PHP会话防止字段编辑

Is it a good idea/good practice to use a PHP session variable to protect against users editing hidden/input field values? For instance, lets say I have the following fields:

<input type="hidden" object_id="1" />
<input type="text" object_id="2" />
etc...

I need to have the object_id on the front end so I can tell which database entries need to be manipulated when the user submits (providing they are authorized to act on the data). The $_SESSION variable would look something like [obj_id = 1, obj_id = 2]. Part of the authorization process makes sure that all of the entries the user is trying to act upon are present in the session. If there is some discrepancy (e.g. an element with object_id="3") the user is not authorized.

Are there solutions that are more widely accepted or does something similar to this usually suffice?

  • 写回答

1条回答 默认 最新

  • douliao8760 2015-12-21 22:49
    关注

    Generally, you still need to trust the end user to provide you with the correct data to be modified. The only thing that you can verify in that context is that the values provided look like valid data to be inserted into the database, and this is usually the databases job itself, as what is valid data is the database table's state to determine.

    There are many ways to approach this. Unless I knew more about what you are trying to do, I cannot provide a sound detailed solution.

    Good luck

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?