Re: RE: unserialize() unexpectedly returns a boolean

From: Date: Fri, 19 Jan 2001 17:59:09 +0000
Subject: Re: RE: unserialize() unexpectedly returns a boolean
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-35663@lists.php.net to get a copy of this message
On Fri, 19 Jan 2001, TR Henigson wrote: > My original e-mail, unanswered, is referenced below. I am in serious > need of HELP. > > To prevent the $SESSION variable from getting set to a boolean, I > wrote the following loop with the idea that if the error happened > in unserializing the data in the database, I would simply query the > database again, and unserialize the data anew: > > while(gettype($SESSION)<>"array") > { > $sessionError++; > $select=new dbLOCAL; > $query="SELECT data FROM sessions WHERE id='".$sessid."'"; > $select->query($query); > $select->next_record(); > $SESSION=unserialize($select->Record["data"]); > echo $select->Record["data"]; > echo "<br>"; > echo gettype($SESSION); > echo "<br>"; > } > > $select is obviously an object. The next_record() method uses the > mysql_fetch_array() function to get put the data into the Record > property. I added the echo statements to see what was happening if > and when the loop executed. Well, it eventually did and I had to > physically terminate the script in my browser as the conditional > for the loop never evaluated TRUE. Echoed out to my browser was > the following: > > > a:2:{s:4:\"USER\";a:15:{s:8:\"loggedIn\";i:1;s:7:\"user_id\";s:1:\"1\";s:5:\ > > "admin\";s:3:\"Yes\";s:10:\"contact_id\";s:1:\"1\";s:5:\"first\";s:2:\"AA\"; > > s:4:\"last\";s:8:\"Aaaaaaaa\";s:7:\"company\";s:3:\"ABC\";s:6:\"street\";s:1 > 8:\"8158 AAAAAA Avenue\";s:4:\"city\";s:11:\"Los > > Angeles\";s:5:\"state\";s:1:\"5\";s:7:\"zipcode\";s:5:\"00000\";s:7:\"countr > y\";s:13:\"United States\";s:5:\"phone\";s:14:\"(000) > > 000-0000\";s:3:\"fax\";s:0:\"\";s:5:\"email\";s:13:\"ted@3bits.com\";}s:7:\" > > CONTACT\";a:1:{i:1;a:11:{s:5:\"first\";s:2:\"AA\";s:4:\"last\";s:8:\"Aaaaaaa > > a\";s:7:\"company\";s:3:\"ABC\";s:6:\"street\";s:18:\"8158 > AAAAAA > Avenue\";s:4:\"city\";s:11:\"Los > > Angeles\";s:5:\"state\";s:1:\"5\";s:7:\"zipcode\";s:5:\"00000\";s:7:\"countr > y\";s:13:\"United States\";s:5:\"phone\";s:14:\"(000) > > 000-0000\";s:3:\"fax\";s:0:\"\";s:5:\"email\";s:13:\"ted@3bits.com\";}}} > boolean > > a:2:{s:4:\"USER\";a:15:{s:8:\"loggedIn\";i:1;s:7:\"user_id\";s:1:\"1\";s:5:\ > > "admin\";s:3:\"Yes\";s:10:\"contact_id\";s:1:\"1\";s:5:\"first\";s:2:\"AA\"; > > s:4:\"last\";s:8:\"Aaaaaaaa\";s:7:\"company\";s:3:\"ABC\";s:6:\"street\";s:1 > 8:\"8158 AAAAAA Avenue\";s:4:\"city\";s:11:\"Los > > Angeles\";s:5:\"state\";s:1:\"5\";s:7:\"zipcode\";s:5:\"00000\";s:7:\"countr > y\";s:13:\"United States\";s:5:\"phone\";s:14:\"(000) > > 000-0000\";s:3:\"fax\";s:0:\"\";s:5:\"email\";s:13:\"ted@3bits.com\";}s:7:\" > > CONTACT\";a:1:{i:1;a:11:{s:5:\"first\";s:2:\"AA\";s:4:\"last\";s:8:\"Aaaaaaa > > a\";s:7:\"company\";s:3:\"ABC\";s:6:\"street\";s:18:\"8158 > AAAAAA > Avenue\";s:4:\"city\";s:11:\"Los > > Angeles\";s:5:\"state\";s:1:\"5\";s:7:\"zipcode\";s:5:\"00000\";s:7:\"countr > y\";s:13:\"United States\";s:5:\"phone\";s:14:\"(000) > > 000-0000\";s:3:\"fax\";s:0:\"\";s:5:\"email\";s:13:\"ted@3bits.com\";}}} > boolean > > AND SO ON... > > Can anyone please tell me why this is happening and what I can > do to correct it??? Thank you, > > Ted > Yeah, there's your problem. See the output? See all those backslashes? Figured it out yet? :) All those backslashes are breaking the unserialization. Use stripslashes(). Or better yet, turn off magic_quotes_runtime in php.ini. -- Ignacio Vazquez-Abrams <ignacio@openservices.net>

« previous php.general (#35663) next »