PHP:POST 数据 +撇号

发布于 2024-08-06 19:17:55 字数 363 浏览 1 评论 0原文

想象一下:

  • 表单数据包含撇号
  • 表单获取提交
  • POST 数据获取序列化
  • POST 数据写入数据库
  • 数据库数据检索
  • 数据无法反序列化

问题出在序列化数据上。我尝试过不使用和使用撇号:

  • s:7:"company";s:12:"Joes company"
  • s:7:"company";s:14:"Joe's company"

我知道 POST 数据会在引号和撇号中添加斜杠但在某个地方我的斜线被删除,这破坏了序列化。我没有在任何地方使用 stripslashes() 函数 - 有什么想法吗?

Imagine this:

  • Form data contains an apostrophe
  • Form gets submitted
  • POST data gets serialized
  • POST data is written to database
  • Database data is retrieved
  • Data cannot be unserialized

The problem is found in the serialized data. I tried without and with an apostrophe:

  • s:7:"company";s:12:"Joes company"
  • s:7:"company";s:14:"Joe's company"

I know POST data adds slashes to quotes and apostrophes but somewhere my slashes are being removed which is breaking the serialization. I'm not using the stripslashes() function anywhere - any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彼岸花ソ最美的依靠 2024-08-13 19:17:55

您确定添加了斜杠吗?仅当启用 Magic Quotes 时才会发生这种情况。

Are you sure the slashes are getting added? That only happens if Magic Quotes is enabled.

世俗缘 2024-08-13 19:17:55

如果您将序列化数据写入数据库并且不使用任何关系或高级数据库功能,则可以在插入数据库之前对序列化数据进行简单的 Base64 编码,并在读回时进行解码。

If you are writing serialized data into the db and not making use of any relations or advanced db functionality, you can simply base64 encode the serialized data before inserting into db, and decode when reading back.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文