sulfurito Posted November 25, 2010 Share Posted November 25, 2010 Hello, I have a call tu function unserialize() in a script that receives a string and has to return an array. In my localhost it works properly but in the server it returns a 1 dimension array with empty value. I'm testing with the string a:1:{s:1:"0";s:8:"value_eq";} The php.ini configuration for magic_quotes is (in both, server and localhost): magic_quotes_gpc Off magic_quotes_runtime Off Other configurations is difficult to compare, as php info is long and very different in local and server. Any ideas where the problem might be? Thank you Quote Link to comment Share on other sites More sharing options...
MrXHellboy Posted November 25, 2010 Share Posted November 25, 2010 Please put your code in here Quote Link to comment Share on other sites More sharing options...
sulfurito Posted November 25, 2010 Author Share Posted November 25, 2010 $fields = 'a:1:{s:1:"0";s:8:"value_eq";}' ; //Actually this is generated by a javascript function, but this is the value that arrives $field_list = unserialize($fields); echo "There are " . count($field_list) . " fields<br>"; echo "First field is " . $field_list[0]; This writes: In localhost: There are 1 fields First field is value_eq In server: There are 1 fields First field is Thank you Quote Link to comment Share on other sites More sharing options...
MrXHellboy Posted November 25, 2010 Share Posted November 25, 2010 I think that how you try to call it is wrong as this works perfectly: <?php $x = serialize(array('value_eq')); $y = unserialize($x); echo $y[0]; ?> You used the PHP serialize function for this $fields ? Quote Link to comment Share on other sites More sharing options...
sulfurito Posted November 25, 2010 Author Share Posted November 25, 2010 No, I use this javascript function, but do you think it matters when it comes from? the parameter I'm using is this $fields = 'a:1:{s:1:"0";s:8:"value_eq";}' ;, and it works in localhost function js_array_to_php_array (a) // This converts a javascript array to a string in PHP serialized format. // This is useful for passing arrays to PHP. On the PHP side you can // unserialize this string from a cookie or request variable. For example, // assuming you used javascript to set a cookie called "php_array" // to the value of a javascript array then you can restore the cookie // from PHP like this: // < ?php // session_start(); // $my_array = unserialize(urldecode(stripslashes($_COOKIE['php_array']))); // print_r ($my_array); // ? > // This automatically converts both keys and values to strings. // The return string is not URL escaped, so you must call the // Javascript "escape()" function before you pass this string to PHP. { var a_php = ""; var total = 0; for (var key in a) { ++ total; a_php = a_php + "s:" + String(key).length + ":\"" + String(key) + "\";s:" + String(a[key]).length + ":\"" + String(a[key]) + "\";"; } a_php = "a:" + total + ":{" + a_php + "}"; return a_php; } Thank you Quote Link to comment Share on other sites More sharing options...
MrXHellboy Posted November 25, 2010 Share Posted November 25, 2010 I am not familiar with Javascript. Absolutely not You have to wait till someone else see this topic... I am sorry Quote Link to comment 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.