dougu5950 2011-08-18 21:41
浏览 27
已采纳

我在数据库中保存数据时是否真的需要使用mysql_real_escape_string?

I am using mysql_real_escape_string to save content in my mySQL database. The content I save is HTML through a form. I delete and re-upload the PHP file that writes in DB when I need it.

To display correctly my HTML input I use stripslashes()

In other case, when I insert it without mysql_real_escape_string, I do not use stripslashes() on the output.

What is your opinion? Does stripslashes affect performance badly ?

  • 写回答

5条回答 默认 最新

  • dongshungai4857 2011-08-18 21:47
    关注

    Do not use stripslashes(). It is utterly useless in terms of security, and there's no added benefit. This practice came from the dark ages of "magic quotes", a thing of the past that has been eliminated in the next PHP version.

    Instead, only filter input:

    • string: mysql_real_escape_string($data)
    • integers: (int)$data
    • floats: (float)$data
    • boolean: isset($data) && $data

    The output is a different matter. If you are storing HTML, you need to filter HTML against javascript.

    Edit: If you have to do stripslashes() for the output to look correctly, than most probably you have magic quotes turned on. Some CMS even made the grave mistake to do their own magic quotes (eg: Wordpress). Always filter as I advised above, turn off magic quotes, and you should be fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理