vineld Posted August 4, 2009 Share Posted August 4, 2009 I have run into problems using serialize / unserialize together with urlencode. In the first file I do this: $a = urlencode(serialize($aArray)); echo count(unserialize(urldecode($a))); This results in the correct number of items in the array. I then send $a to another file where this is done: $a = $_GET["a"]; $a = urldecode($a); echo $a; $aArray = unserialize($a); echo count($aArray); This simply prints 1 and the array has not been restored. What is the problem here? I have simplified the code somewhat, I actually return js for an ajax request in the second file. I have alerted the $a string in the second file, copied it and ran unserialize in another simple php file and then it works... Quote Link to comment https://forums.phpfreaks.com/topic/168810-serialize-unserialize-problem/ Share on other sites More sharing options...
loushou Posted August 4, 2009 Share Posted August 4, 2009 Based on the code snippets that you have written, it seems that in order to solve this problem for you, we are going to need to see more. I dont see anything that sticks out as wrong here so the error has to be elsewhere. Basically we just need to see what is going on around these lines because I suspect that: 1. these lines are not getting executed or 2. the transfer between the two files is not supplying the parameters that you expect chris. Quote Link to comment https://forums.phpfreaks.com/topic/168810-serialize-unserialize-problem/#findComment-890647 Share on other sites More sharing options...
patrickmvi Posted August 4, 2009 Share Posted August 4, 2009 Try not doing the urldecode. I believe that once the data comes across the $_GET, it is automatically decoded. For example, if you pass "hello%20world" as a get parameter and then echo it on the page, it will echo as "hello world" and not "hello%20world". Your urldecode may be destroying some stuff by decoding things that shouldn't be decoded. I could see a definate issue if for instance you have the "%" char anywhere in your serialized array. Also, you probably don't want to be passing entire arrays of stuff via GET unless you have no other alternative. I would stick to session variables for that sort of thing... Quote Link to comment https://forums.phpfreaks.com/topic/168810-serialize-unserialize-problem/#findComment-890654 Share on other sites More sharing options...
vineld Posted August 4, 2009 Author Share Posted August 4, 2009 There isn't really any more code of relevance to show. It's a simple ajax request. Yeah, I am usually using sessions but I wanted to experiment with this alternative in case there is a situation where it would be needed (can't really think of one now though...). It seems as if the $_GET is getting in the way so to speak. I have tried removing the urldecode as well although it makes no difference. I suspect it has to do with the character encoding though. Using sessions it works just fine. Quote Link to comment https://forums.phpfreaks.com/topic/168810-serialize-unserialize-problem/#findComment-890676 Share on other sites More sharing options...
aschk Posted August 4, 2009 Share Posted August 4, 2009 urlencode() 'ing a serialized string and sending it over a GET request for teh facepalm. Quote Link to comment https://forums.phpfreaks.com/topic/168810-serialize-unserialize-problem/#findComment-890682 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.