Result of strange serialize

Asked

Viewed 63 times

1

I did a serialization of an object in .php whose result is very different from the ordinary:

example.com/script.php? first name=joao&last name=silva&endereco=rua+dos+bobos+numero+zero&cpf=11111111111111`)

This being the result:

example.com.php? query=O:8:"Query":4:{s:10:"resultType";s:8:"products";s:6:"search";s:12:"lapis%20pen";s:6:"start";N;s:9:"records";N;}

Code:

$string = serialize($consulta);
$url = 'Location:'.'exibir.php?consulta='.$string;
header($url);

What’s inside the object:

Consulta Object ( [resultType] => produtos [search] => lapis caneta [inicio] => [registros] => )

1 answer

2


It seems to me that you are confusing the function of PHP with that of jQuery. In PHP, the function serialize serves to serialize an object so that it can be stored, and not used in a query string of an HTTP GET request.

For the purpose you need, use http_build_query, that serializes the public properties of an object (also works with arrays).

  • ,@bfavaretto see the result exibir.php?resultType=produtos&search=lapis+caneta the representation is correct? how can I store it directly in the corresponding object?

  • Yes, that’s correct. You can undo the operation with parse_str or parse_url depending on what you pass. Take a look at the documentation of these functions in the PHP manual.

  • Okay, this form of object passage is the most efficient and correct way?

  • It is the only way to pass data via querystring (if I understand what you are asking...)

  • Yes the object contains values to be consulted in a BD

  • why not send normally without serialize?

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.