PHP 反序列化 - 索引错误

发布于 2024-12-26 06:42:24 字数 1161 浏览 4 评论 0原文

我在使用 PHP serializeunserialize 函数时遇到一些困难。我正在使用 serialize(array) 将数组插入 MySQL DB。这是我在数据库中的值

a:4:{i:0;s:29:"k44L1b_bisnode.com.xlarge.png";i:1;s:28:"q44L1b_bisnode.com.large.png";i:2;s:29:"q44L1b_bisnode.com.medium.png";i:3;s:28:"q44L1b_bisnode.com.small.png";}

如果我这样做,

$images = unserialize( $apartment->images );

我会得到错误:ErrorException [Notice]:unserialize() [function.unserialize]:Error at offset 9 of 208 bytes$apartment 是我的 DB ORM 对象,如果我执行 echo $apartment->images 之类的操作,它将向我输出上面的序列化字符串。

但如果我做这样的事情

$images = unserialize( 'a:4:{i:0;s:29:"k44L1b_bisnode.com.xlarge.png";i:1;s:28:"q44L1b_bisnode.com.large.png";i:2;s:29:"q44L1b_bisnode.com.medium.png";i:3;s:28:"q44L1b_bisnode.com.small.png";}' );

它会起作用......嗯? $apartment->images 的 var_dump() 返回

string(208) "a:4:{i:0;s:29:"k44L1b_bisnode.com.xlarge.png";i:1;s:28:"q44L1b_bisnode.com.large.png";i:2;s:29:"q44L1b_bisnode.com.medium.png";i:3;s:28:"q44L1b_bisnode.com.small.png";}"

I am having some difficulties with PHP serialize and unserialize functions. I am inserting array into MySQL DB with serialize(array). This is my value in DB

a:4:{i:0;s:29:"k44L1b_bisnode.com.xlarge.png";i:1;s:28:"q44L1b_bisnode.com.large.png";i:2;s:29:"q44L1b_bisnode.com.medium.png";i:3;s:28:"q44L1b_bisnode.com.small.png";}

If I do something like this

$images = unserialize( $apartment->images );

I will get error: ErrorException [ Notice ]: unserialize() [function.unserialize]: Error at offset 9 of 208 bytes. $apartment is my DB ORM object and if I do something like echo $apartment->images it will output me the above serialized string.

But if I do something like this

$images = unserialize( 'a:4:{i:0;s:29:"k44L1b_bisnode.com.xlarge.png";i:1;s:28:"q44L1b_bisnode.com.large.png";i:2;s:29:"q44L1b_bisnode.com.medium.png";i:3;s:28:"q44L1b_bisnode.com.small.png";}' );

It will work... Huh? var_dump() of $apartment->images returns

string(208) "a:4:{i:0;s:29:"k44L1b_bisnode.com.xlarge.png";i:1;s:28:"q44L1b_bisnode.com.large.png";i:2;s:29:"q44L1b_bisnode.com.medium.png";i:3;s:28:"q44L1b_bisnode.com.small.png";}"

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

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

发布评论

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

评论(1

等往事风中吹 2025-01-02 06:42:24

来自 FuelPHP 的一个人注意到了这个 http://docs.fuelphp.com/general/views .html#/security 所以这是我的问题。

安全
默认情况下,视图使用输出编码来清理您使用 Security::htmlentities() 传递给它们的任何内容。如果你想传递未经过滤的内容,可以使用方法 set($name, $value, false)。

A guy from FuelPHP noted on this http://docs.fuelphp.com/general/views.html#/security so this was my issue.

Security
By default, Views use output encoding to sanitize anything you pass to them using Security::htmlentities(). If you want to pass something unfiltered, you can use the method set($name, $value, false).

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