What do a question mark (?) and an ampersand (&) mean in a URL?

橙三吉。 提交于 2020-07-05 03:20:07

问题


I saw a link like this:

https://www.google.com/recaptcha/api/siteverify?secret=YOUR_SITE_KEY&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);

I know that it's setting the secret variable to YOUR_SITE_KEY and response to response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR'] but, I'm not sure what those symbols means that is, the ? and & in the query string.


回答1:


There isn't really anything there that is particular to PHP.

The ? indicates the start of the query string. Within the query string you have a set of key=value pairs, each separated by an &.

PHP will populate $_GET with this data. It is part of the URL standard and any server side language will have a parser that provides similar functionality.

This is also the default data format browsers generate when submitting a form.




回答2:


When used as part of a URL, ? and & represent key value pairs that make up the Query String, which is a set of information sent to the server.

The query string starts after the end of the page being requested with a ? and then a key value pair like:

?variable1=value1

Any additional key/value pairs need to be prefaced with & like:

?variable1=value1&variable2=value2&variable3=value3



回答3:


In HTTP request, there are either GET or POST request types and the basic difference in these requests is, how parameters/values are send in the HTTP request. However in GET request, parameters are attached to URL.

For e.g. http://xlntstudios.com/index.php is the url and after url symbol ? tells, anything after the ? has parameters passed to URL in key/value pairs. Where as each key=value pair is separated by & symbol.

http://xlntstudios.com/index.php?name=Atul&age=31&city=Portland

so here key/value pairs are

name=Atul
age=31
city=Portland

each one separated by & symbol.



来源:https://stackoverflow.com/questions/38252310/what-do-a-question-mark-and-an-ampersand-mean-in-a-url

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