diggersworld
diggersworld

Reputation: 13090

Passing multiple values for same GET variable in URL

I'm wondering if there is a cleaner way to pass multiple variables in a GET request than the following:

http://www.mysite.com/somepage?tags[]=one&tags[]=two&tags[]=three

I had thought about the following:

http://www.mysite.com/somepage?tags=one,two,three

Then using explode() to separate them.

Wondered if anyone had seen or used a better solution though?

Upvotes: 2

Views: 9342

Answers (4)

ArendE
ArendE

Reputation: 997

I suggest using mod_rewrite to rewrite like www.website.com/tags/tag1-tag2-tag3 or if you want to use only php www.website.com/tags.php?tags=tag1-tag2-tag3. Using the '-' makes it searchengine friendly (as for tags is often useful) and is also not as commonly used as a comma (thinking of the tagging itself).

Upvotes: 0

safarov
safarov

Reputation: 7804

i think the best solution is using json_encode(). But if you want to look nice (as a single string). You can encyrpt code to look like page?tags=HuH&ITBHjYF86588gmjkbkb. Simplest of doing it is

$tags = base64_encode(json_encode($tags_array));

Upvotes: 0

Michael
Michael

Reputation: 12836

Using explode() is only reliable if the values of each tag will never contain whatever string it is you're exploding by (in this case ",").

I'd say it's safer to use tags[]=X&tags[]=Y.

Upvotes: 3

Tei
Tei

Reputation: 1416

you can urlencode(json_encode(yourData)), then on the server json_decode

this solution will work with any complex data you may need to pass, not just the simple one you have here.

Upvotes: 1

Related Questions