Grab an array from a cookie without throwing errors?

From: Date: Fri, 08 Oct 2004 15:43:58 +0000
Subject: Grab an array from a cookie without throwing errors?
Groups: php.general 
Request: Send a blank email to php-general+get-198977@lists.php.net to get a copy of this message
I've got a cookie that's either non-existent or a serialized array. I'm trying all sorts of different code combinations to retrieve it into an array variable, but everything I try throws up some combination of notices and/or warnings. Here is my latest & greatest: $cookie = $_COOKIE['bookmarks']; if(unserialize($cookie) == true) { $bookmarks = unserialize($cookie); } else { $bookmarks = array(); } Produces: Notice: Undefined index: bookmarks in c:\Inetpub\wwwroot\palms\htdocs\bookmarks.php on line 5 Notice: unserialize() [function.unserialize]: Argument is not an string in c:\Inetpub\wwwroot\palms\htdocs\bookmarks.php on line 5 Any suggestions on how I can do this without throwing notices? I'm aware that I can turn notices off but I like them kept on to help me with debugging. - Brian

« previous php.general (#198977) next »