简体   繁体   中英

Special chars in serialized object are destroying PHP session

After login of the user I serialize the user object and store it in his session just like this

$_SESSION['User'] = serialize($this);

so I have faster access to his data in further steps.

Now, sometimes users can't stay logged in because their session is immediatly destroyed with the next page request. I found that it is because of special chars the user stored in his data. Eg in one case there were some sweet hards in a notice

s:72:"♥ Aufsicht ♥ <br>...;"

In another case a phone number was copied from Apple contacts and so on. Are there restrictions to storing in sessions, like only ASCII chars? Do I have to convert the whole string in another format, eg Base64? Or how to handle this best? Thanx.

Thanks a lot to Sammitch for the note in his comment: problem was the pre-serialization. If I just assign the object to the $_SESSION like

$_SESSION['User'] = $this;

it is no problem if a field of the object contains those characters

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM