Page 1 of 1

Passing Arrays in URLs - A Better Way?

Posted: Thu Sep 11, 2003 3:32 am
by alexp
Passing Arrays in URLs. I.e passing arrays between two pages.

This has been delt with before but I can't help feeling there is a better way. The current options are:

serialize and urlencode .... then ... urldecode and unserialize

OR

implode ... then ... explode

OR

use session variables/cookies

But if you create a form with a multiple select in it like so:

<SELECT NAME=selectname[]> etc

.. the array $selectname appears automatically in the backend when the form is submitted. Note that $selectname is an array. This means that php must automatically create arrays from data POSTed in a particular format.

If we could pass an array in this format in a url or a hidden form then we wouldn't have to do anything on the recieving page.

Anyone know what this format is?

Re: Passing Arrays in URLs - A Better Way?

Posted: Thu Sep 11, 2003 3:45 am
by twigletmac
alexp wrote:Anyone know what this format is?
Sessions. You have three choices for passing data between pages - GET, POST and sessions/cookies, only sessions can pass arrays without any manipulation needed on either end of the processing.

Mac

Posted: Thu Sep 11, 2003 4:00 am
by alexp
But the multiple select array is not passed using session cookies - it is passed in the POST along with all the other variables - and it is reconstructed automatically by PHP at the other end. Clearly there is some formatting of a POST variable that triggers the PHP engine into processing it as an array.