在URL中传递相同GET变量的多个值

时间:2022-01-16 02:28:26

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

我想知道在GET请求中是否有更简洁的方法来传递多个变量,而不是以下方法:

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.

然后使用explode()分隔它们。

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

想知道是否有人见过或使用过更好的解决方案?

4 个解决方案

#1


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

使用explode()只有在每个标记的值永远不会包含您正在爆炸的任何字符串(在本例中为“,”)时才可靠。

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

我会说使用标签[] = X&tags [] = Y更安全。

#2


1  

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

你可以在urlencode(json_encode(yourData)),然后在服务器json_decode上

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

此解决方案适用于您可能需要传递的任何复杂数据,而不仅仅是您在此处使用的简单数据。

#3


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

我认为最好的解决方案是使用json_encode()。但如果你想看起来不错(作为单个字符串)。你可以将代码看起来像页面吗?tags = HuH&ITBHjYF86588gmjkbkb。最简单的做法是

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

#4


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

我建议使用mod_rewrite重写,如www.website.com/tags/tag1-tag2-tag3,或者如果你只想使用php www.website.com/tags.php?tags=tag1-tag2-tag3。使用' - '使其对searchengine友好(对于标签通常很有用)并且也不像逗号那样常用(考虑标记本身)。

#1


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

使用explode()只有在每个标记的值永远不会包含您正在爆炸的任何字符串(在本例中为“,”)时才可靠。

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

我会说使用标签[] = X&tags [] = Y更安全。

#2


1  

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

你可以在urlencode(json_encode(yourData)),然后在服务器json_decode上

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

此解决方案适用于您可能需要传递的任何复杂数据,而不仅仅是您在此处使用的简单数据。

#3


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

我认为最好的解决方案是使用json_encode()。但如果你想看起来不错(作为单个字符串)。你可以将代码看起来像页面吗?tags = HuH&ITBHjYF86588gmjkbkb。最简单的做法是

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

#4


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

我建议使用mod_rewrite重写,如www.website.com/tags/tag1-tag2-tag3,或者如果你只想使用php www.website.com/tags.php?tags=tag1-tag2-tag3。使用' - '使其对searchengine友好(对于标签通常很有用)并且也不像逗号那样常用(考虑标记本身)。