What is the purpose of passing variables through a URL?

Posted on 2011-10-18
Medium Priority
Last Modified: 2012-05-12

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
Question by:techin4
LVL 17

Accepted Solution

sonawanekiran earned 500 total points
ID: 36984785
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
LVL 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 500 total points
ID: 36984808
Here is a paper on POST and GET from the W3C standards organization: http://www.w3.org/2001/tag/doc/whenToUseGet-20040321
LVL 20

Assisted Solution

edster9999 earned 500 total points
ID: 36984883
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.

LVL 34

Assisted Solution

by:Beverley Portlock
Beverley Portlock earned 500 total points
ID: 36985294
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).

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question