What is the purpose of passing variables through a URL?


I am new to PHP and was wondering if someone can explain to me the purpose of passing
a variable through a URL? I'm having some difficulty understanding why we do this.

Can you give me an example of when this would come in handy?

Thank You
Who is Participating?
Kiran SonawaneProject LeadCommented:
In web programming language it is termed as querystring

The geeneral form of a web address is URL + Querystring. Together, these values are called an Universal Resource Identifier, or URI. The Querystring is anything in the URI that appears after the '?' sign. So, in the below URI:

http://www.seoknowhow.com/ testpage.php?ID=1234
the querystring is "ID=1234"

This means that  when you are accessing testpage.php you can access value 100 at testpage.php. Accessing querystring varies according to language you are using. Suppose testpage.php shows all employees  having manager "xyz" then you should know the id of that manager. Using querystring you can pass the any values using value-pair
Dave BaldwinFixer of ProblemsCommented:
Here is a paper on POST and GET from the W3C standards organization: http://www.w3.org/2001/tag/doc/whenToUseGet-20040321
When you submit data (ie there is a form on the internet and you fill in the boxes like 'name' and 'address') the data gets passed back to the web server using one of two methods.

The one you use is set inside the form page.

If you do POST the data gets embedded into a page and sent back to the server.
If you do get it is tagged onto the end of the URL as above.

Why would you use these different methods?
POST allows you to embed much more data.  You can send pretty much anything this way. If you have a page where you upload a graphic then this (may) use POST.  It also makes it look nicer and is not so obvious to the user that data is flyong back and forth.
GET is for simple text passing back to the server and the one really useful bit about it is for the userbookmarking a page.
If you ask the user what town they live in and this then results in a page of results for that road then the results page (using the GET method) would be something like -
They can book mark that to go straight back to the results and not have to fill in the form again.

Beverley PortlockCommented:
In simple terms, we pass data through the URL to get it from Page 'A' to Page 'B'

If the pages are in the same website then other mechanisms, such as sessions, are available. If the pages are in different websites then short of using highly complex mechanisms like SOAP, the simplest way is to pass the data either by POST or by GET (in the URL).
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.