Jump to content

Unserialize() doesn't work in server (does in local)


sulfurito

Recommended Posts

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

$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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.