Problem with unserialize in php

I am using serialize / unserialize functions in php 5.2. the text to be saved is sent via the form. btw, with no spaces before or after. if the text contains "or", it is serialized successfully. The problem is that it does not cancel the repetition. What am I doing wrong?

+4
source share
4 answers

David Walsh has a simple solution:

//to safely serialize $encoded_serialized_string = base64_encode(serialize($your_array)); //to unserialize $array_restored = unserialize(base64_decode($encoded_serialized_string)); 

http://davidwalsh.name/php-serialize-unserialize-issues

+8
source

these are magical quotes, probably in response to such behavior. Thus, in order to perform non-serialization, you may have to do stripslashes () first:

 if (get_magic_quotes_gpc()) $data = stripslashes($data); 

although it is almost impossible to have magic_quotes in 5.2 ...
To say something specific, you need to find the difference between the original and returned data.

But anyway, why don't you use sessions instead of sending data to and from the browser? Sessions are really faster and safer.

+4
source

When you serialize, you should use addslashes , and when you non- stripslashes , use stripslashes .

Example:

 if (get_magic_quotes_gpc()) { serialize($variable); } else { addslashes(serialize($variable)); } if (get_magic_quotes_gpc()) { stripslashes(unserialize($variable)); } else { unserialize($variable); } 
+1
source

Adding a slash to the quotes solves the problem. Check out my code: http://codepad.org/7JWa2BT6

0
source

Source: https://habr.com/ru/post/1310606/


All Articles