4 Replies Latest reply on Jan 22, 2008 12:24 PM by Newsgroup_User

    Parsing URL Variables

    alison@ut
      I have a page (not on my server) that links to a page on my server.

      This URL has several variables that I want to grab and use on my page. The URL looks like this:

      http://www.somedomain.org/test.cgi?id=ABC&isbn=1234&volume=82

      By using cgi.HTTP_REFERER I am able to display the URL, but I am having trouble parsing out the variables to use later on the page.

      How do I "grab" the values of id, isbn, and volume from this URL?

      Thank you for your help.
      Alison
        • 1. Re: Parsing URL Variables
          Dan Bracuk Level 5
          Use list functions. The url is a nested list. The outer list has an ampersand delimiter and the inner lists have an equal sign delimiter.
          • 2. Re: Parsing URL Variables
            Level 7
            alison@ut wrote:
            > I have a page (not on my server) that links to a page on my server.
            >
            > This URL has several variables that I want to grab and use on my page. The
            > URL looks like this:
            >
            > http://www.somedomain.org/test.cgi?id=ABC&isbn=1234&volume=82
            >
            > By using cgi.HTTP_REFERER I am able to display the URL, but I am having
            > trouble parsing out the variables to use later on the page.
            >
            > How do I "grab" the values of id, isbn, and volume from this URL?
            >
            > Thank you for your help.
            > Alison
            >

            Most of us would use url.id, url.isbn and url.volume. You could also
            use url['id'], url['isbn'] and url['volume'] if you like on any version
            of ColdFusion released this century.

            <cfdump var="#url#"> may also be informative.

            I.E. you are working to hard if you are trying to parse
            cgi.http_REFERER. ColdFusion has already done this and dumped
            everything into the URL structure. Of course, if I was going to use a
            CGI variable, I would use cgi.query_string and parse as nested lists.

            But is 'test.cgi' a ColdFusion template?

            • 3. Re: Parsing URL Variables
              alison@ut Level 1
              Thank you both for your replies!

              The referring page is not a CF page, so i guess I will need to parse the URL using cgi.query_string. I will look for information on how to do that since I have never used that before.

              Thanks again!
              Alison
              • 4. Re: Parsing URL Variables
                Level 7
                alison@ut wrote:
                > Thank you both for your replies!
                >
                > The referring page is not a CF page, so i guess I will need to parse the URL
                > using cgi.query_string. I will look for information on how to do that since I
                > have never used that before.
                >
                > Thanks again!
                > Alison
                >

                The referring page has nothing to say about this. If the page on your
                server is a CFML page, then the URL variables will be in the URL
                structure. ColdFusion handles this behind the scenes whenever a request
                is made, no matter where the request comes from, ColdFusion doesn't care.