Jump to content

Best way to pass a lot of data with GET


Recommended Posts

Hi ! I need to pass a lot of variables using GET, and many of them are related, so I was thinking in two options:

1) Pass them as array:



2) Pass them in a single parameter, and split it in PHP (a custom and simpler serializer)



What do you think is better? (or maybe there is a 3rd option...)

The second method seems more readable and short, the first easier to construct and maybe faster because we don't need to "unserialize".

But I'm looking for better reasons.

I'm thinking in a possible advantage of the first method over the second for SEO, because if Google is smart enough to understand that categories[] are all the same, then can understand that:


is equal to:


I think that is more difficult for Google to understand that with:







Link to comment
Share on other sites

Yes, the problem is that I never see a URL like that, with arrays, but I see frequently the other URL style.

And that make me think that maybe I'm doing something wrong.

Do you know any big site with array in their URLs?



Link to comment
Share on other sites

Well, I was trying the URLs with brackets, and I was happy because php has two very useful functions for that:




but with the last one we get a result like this:



It's a real pain, because the brackets ( "[ ]" ) are escaped.

I was planing to "unescape" the brackets, but according to RFC 3986 and later on section "3.2.2.  Host" we learn in the fourth paragraph that:

"A host identified by an IP literal address … is distinguished by enclosing the IP literal within square brackets ("[" and "]").  This is the only place where square bracket characters are allowed in the URI syntax."


So square brackets in our uri query will make it invalid.

Maybe that's the reason because is not frequent to see URLs with arrays, because they are very long, agly and confusing.


Link to comment
Share on other sites

I used arrays in a couple of pages that ask "how many" and pushes that count into an array.




the key was implementing the array in the form:  in the above page it asks how many disabilities and then builds an array for the form - <select name="percent[]">


Probably not the best example but arrays are easier to work with because you can change the size and use key pairs if needed to extract your data.  I know there is a smaller limit on GET than POST but not sure what it is.

Link to comment
Share on other sites

The max size for max browsers's compatibility in GET parameters is near 2KB.

That's enough for almost any application but the problem is that 2KB of URL is not very user friendly I guess...

You can see another problem with arrays in URLs, the link in your post is not correct because the forum doesn't link all the URL.


I think human readability is important too, that's why "friendly and pretty urls" exists.

And a URL like this:


doesn't look very friendly.


array in ugly urls is the fastest and easiest way, but, is it the best? I don't know :(


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.