3

Would like some help to understand this URL a little better.

something/?page=2&agent=2725

I'm aware that with $_GET["page"] I can get the 'page' number and presumably 'agent' code also via the same approach.

I'm trying to understand the role of the '&' symbol there. By the outlook I can guess it combines page number and the agent code. Is my understanding there right?

What instance you can use this & symbol and how is it helpful?

Mohan Wijesena
  • 225
  • 1
  • 3
  • 11
  • 2
    Its simply the syntax. & is the separator between two GET parameters in the URL. Means, as you said, `$_GET["page"]` would be 2 and `$_GET["agent"]` would be 2725. They have nothing to do together and the "&" symbol shoudln't be interpreted as a "AND... its more like a separator. Like you would write `page: 2, agent: 2725` ... in this case the `,` is the `&`. Hope you understand. Don't let you confuse from this symbol. – Twinfriends Mar 10 '17 at 09:36

3 Answers3

1

Let’s look at this HTTP URI:

http://example.com/something/?page=2&agent=2725#foo

This is the URI’s query component (indicated by the first ?, terminated by the first # or the end of the URI):

page=2&agent=2725

As far as the general URI syntax is concerned, the & is not different from the p, the a, or the = (see all allowed characters): they all represent data in the query component.

A common convention is to use the query component for name–value pairs. In this convention, the & is used as delimiter, separating the pairs:

name1=value1&name2=value2&name3=value3
Community
  • 1
  • 1
unor
  • 92,415
  • 26
  • 211
  • 360
0

the "?" means: Get-Parameters are following, the "=" seperates key and value and the "&" seperates different keys with their corresponding value. So, the "&" just means "there is another Get-Parameter following".

test.php?key1=value2&key2=value2&key3=value3&...

mfnalex
  • 833
  • 5
  • 16
0

& this symbol is used to separate each parameters on the URL. So basically when the request params is parsed by the server, it knows that every & is another variable.

Also this format is known as urlencoded.

You can check and read more here. URLENCODED

Reyan Tropia
  • 140
  • 1
  • 10