What is the purpose of passing variables through a URL?

Posted on 2011-10-18
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

    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: 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 82

    Assisted Solution

    by:Dave Baldwin
    Here is a paper on POST and GET from the W3C standards organization:
    LVL 20

    Assisted Solution

    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.

    POST and GET
    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
    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

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    Read about why website design really matters in today's demanding market.
    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…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now