Question

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";}"
Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top