Serialize/Unserialize Arrays with GET Method--Broken Serialize??

From: Date: Thu, 21 Dec 2000 08:25:23 +0000
Subject: Serialize/Unserialize Arrays with GET Method--Broken Serialize??
Groups: php.general 
Request: Send a blank email to php-general+get-31377@lists.php.net to get a copy of this message
Folks, I just spent many hours debugging why my array would not work with GET method in URL; THIS WAY SHOULD WORK------------------------------------------BUT DOESN'T if(getenv("REQUEST_METHOD")=="POST"){ $posted=$HTTP_POST_VARS; $posted=urlencode(serialize($posted)); //******* This is the best way... //print link to same page now passing array of $posted(this has been serialized/urlencoded) with GET method in URL print "<a href=\"page.php?posted=$posted\">Pass posted variable to same page.php</a>\n"; }else{ //page is from GET $posted=unserialize(urldecode($posted)); print "Variable 'posted' is type =>". gettype($posted) . "\n"; //*******THIS KEEPS RETURNING 'STRING'!!!! WTF?? } ----------------------------HERE'S WHAT I HAD TO DO TO GET IT TO RETURN AS AN ARRAY---------- I noticed that somehow (maybe Magic Quotes gpc=on in php.ini???) It was adding slashes to the serialized string!! So, on return of the page from clicking on the link I had to do this-> $posted=unserialize(stripslashes($posted)); //******notice the STRIPSLASHES!! AND, I didn't have to URLDECODE! print "New GET Unserialized is <br>".gettype($posted)."<br>"; //********now returns ARRAY!!! YIPPEEE!! ------------------------------------------------------- Just want to post this here so others suffering the same problems will have a fix as I just thought the serialize function was broke :) John Hanson

« previous php.general (#31377) next »