HTTP query string and []

穿精又带淫゛_ 提交于 2019-12-10 22:33:17

问题


PHP uses [] in query parameter names to ensure that multiple occurrences of a parameter are all present in $_GET superglobal variable. (Otherwise only last occurrence is present.) (Any other software does that?)

But from RFC 3986 (and others as well) it seems that neither [ nor ] are allowed in query string.

Yet my experiments with various browsers suggested that no browser encodes those characters and they are there in the URI just like that...

Is this real life practice? Or am I testing it incorrectly? I tested with PHP 5.3.17 on IIS 7. Using Internet Explorer, Firefox and Chrome. Then I compared what is in $_SERVER['QUERY_STRING'] and $_GET.


回答1:


It is common practice. It's a way of passing arrays in to the back-end script, and works with ASP and PHP (Never tested with ASP.net, but was common practice when I used ASP back in ~2004). As far as I know, there is not another way to pass an array to your script unless you use javascript and .join or something similar.

You can view http://www.thefutureoftheweb.com/blog/use-arrays-with-html-form-inputs as one of the references of how to use arrays within your HTML forms to be passed to your backend. Though, to be fair, most of the time they are used in conjunction with 'POST' rather than 'GET'.



来源:https://stackoverflow.com/questions/12928173/http-query-string-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!