Passing Arrays in URLs - A Better Way?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alexp
Forum Newbie
Posts: 11
Joined: Thu Sep 11, 2003 3:32 am

Passing Arrays in URLs - A Better Way?

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Re: Passing Arrays in URLs - A Better Way?

Post 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
alexp
Forum Newbie
Posts: 11
Joined: Thu Sep 11, 2003 3:32 am

Post 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.
Post Reply