Every website has a url (uniform resource identifier)/ unique readable web link.

The link points you to the web server and the web page you are looking for.

Lets understand the format of any web url:

http://www.gotomywebsite.com/products.aspx

http:// indicates you are using Http protocol for transfer of messages across the web.

The first part of the web url i.e. the text before the .com or .gov or .co is called the ‘domain’.

Any domain name is mapped to an IP address, most likely it’s web server address. This information is available on DNS servers.

There is a ‘/’ followed after the domain name, as you can notice in the example above. Note that, if there is ever any text after the domain name in the url, it is always followed by ‘/’

Then after the ‘/’ you see the web directory name, that the url is pointing to, which in this case is ‘products’.

If your webpage is developed so as to accept query string parameters using Http GET method, then an example of your url would look like this:

http://www.gotomywebsite.com/products.aspx?prd_name=bed-lamp&prd_id=933ap31&category=furniture

What you see above, is a web url with Get parameters and their corresponding variable values.

Remember that, GET method parameter values are transmitted as text.

No matter what web technology is used to develop your website , the web technology has in built classes to read Http data. PHP, JavaScript, Asp.net etc all these languages will have in built functions to read the data received through Http GET method.

Also, it is important to note that, the data passed as url query parameter values using GET method is not secure. Many browsers by default save the browsing history. Which means, any user using your system can view the url and passed parameters. GET requests can be cached and bookmarked.

There are a lot of hackers and bots that are programmed to read and manipulate url query parameters.

So unless, the data you are passing, is not private information, you can use GET method to transmit messages.

How do I send query parameters and variable values ?

  1. If your url is only consists of the domain name, then just after the domain, use ‘/?’ followed by your parameter name.
  2. If the url contains a root directory after the domain name e.g.  http://www.abcde.com/read.html
  3. Then at the end of the url use ‘/’ and then your parameter name
  4. To pass a value to your parameter name, simple put ‘=’ after the parameter name and pass the value.  e.g. http://www.abcde.com/read.html?user_name=tom
  5. When you pass multiple parameters, then separate them with ‘&’
  6. e.g. http://www.abcde.com/read.html?user_name=tom&device=laptop&model=dell-7400

 

You just learned 2 syntax forms for query strings:

http://www.abcde.com/?user_name=tom&device=laptop&model=dell-7400

http://www.abcde.com/read.html?user_name=tom&device=laptop&model=dell-7400

The url parameters may get populated when a user takes an action on a website, for e.g. clicks a button or downloads a file maybe.

Now that you know, how a query string is formulated and how necessary data is passed to the web server of the web page, the next is to know how the web server retrieves this data from the web request url. The web server when receives this url through Http protocol and will break down the url and extract each parameter value.

As stated earlier, any web technology has built in classes and functions to read Http data.

Most web languages save the query parameters and their values as Name-Value collection objects. Please refer to the coding language guideline documents to know which functions and what syntax to use to retrieve query string values.

 

Suggested Reads:

Syntax for Query strings

Retrieving QueryString values in Asp.net

Retrieving QueryString values in PHP

Limitations of GET method