2

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?

3
  • 1
    How about http:/who.cares/page.php?tags=lorem+ipsum+sit+dolor+amet .. or with mode rewrite: http://who.cares/tags/lorem+ipsum+sit+dolor+amet. With urldecode() and explode on ' '. Commented Mar 30, 2012 at 10:57
  • Why would you want to do so? The mechanism works; Every mechanism you will invent will have it's flaws, but then you are on your own. Commented Mar 30, 2012 at 10:57
  • @twall: to make it look nice for the user if it ever used as a link etc. Commented Mar 30, 2012 at 11:03

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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));

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.