note 15710 added to function.unserialize

From: Date: Thu, 27 Sep 2001 11:31:46 +0000
Subject: note 15710 added to function.unserialize
Groups: php.notes 
Request: Send a blank email to php-notes+get-18368@lists.php.net to get a copy of this message
When you serialize a variable using serialize(addslashes(variable)) before placing it into a MySql database, just use unserialize(variable) and not unserialize(stripslashes(variable)) when attempting to retrieve it. The reason is that MySql will remove the slashes anyway when it stores the variable. All that happens when you strip slashes on the retrieved variable is that you are setting yourself up for a failed unserialize. Say you had r/3 as one of your entries and this becomes r3 after the strip slashes, unserialize will fail. So: unserialize(variable) not unserialize(stripslashes(variable)) when retrieving from MySql database. -- http://www.php.net/manual/en/function.unserialize.php http://master.php.net/manage/user-notes.php?action=edit+15710 http://master.php.net/manage/user-notes.php?action=delete+15710 http://master.php.net/manage/user-notes.php?action=reject+15710

« previous php.notes (#18368) next »