4 Replies Latest reply on Apr 4, 2008 4:55 PM by Dinghus

    parsing cgi.path_info

    jqcf Level 1
      Let's say you have a url like this: /page.cfm/var1.valueofvar1-var2.valueofvar2-var3.valueofvar3
      And in some cases, the url is something like this: /page.cfm/var1.valueofvar1-var2.valueofvar2-var3.valueofvar3?gclid=239084327akdfgj

      And, all you really care about is getting the value of var3. How might you write some code to get the value of var3?
      Here's some code I came up with that actually seems to work:
      <cfset var3 = ListLast(cgi.PATH_INFO,".")>

      But, I'm not sure this all is good practice really. So far, it seems to work without any problems that I can forsee. Anyone else find a problem with this?
        • 1. parsing cgi.path_info
          Kronin555 Level 1
          If you're guaranteed that var3 will always be the last var, then that should work. Seems very fragile to me, though. What if one day you change one of the links going to that page to include another variable? and the code you just wrote that assumes var3 is always the last variable is overlooked? now you're getting the 4th variable's value.

          That whole method seems fragile. You can't have any periods or dashes in your variable values, or it breaks. What if you ever want a variable name with a dash in it?
          • 2. Re: parsing cgi.path_info
            Dan Bracuk Level 5

            Originally posted by: Kronin555
            What if you ever want a variable name with a dash in it?

            Something like this:
            Invalid CFML construct found on line 16 at column 8.
            • 3. parsing cgi.path_info
              Kronin555 Level 1
              Dan, I wasn't talking about a CF variable. I was talking about a variable in the form that jqcf is using.


              If var1's name wasn't var1, but was, for sake of argument, "my-var", then the URL becomes:


              Now all of a sudden you can't use "-" as a delimiter between your variable.value pairs.

              I know CF doesn't support variable names with dashes. Doesn't mean you can't use them elsewhere. Your form field names can include dashes, URL variables can include dashes, etc.

              If you do have a URL variable with a dash in it, you can access it as:

              I was simply saying that putting variables in the URL the way jqcf is asking about seems very fragile to me. The dash in a variable name was just an example. The method he's using, his variable values can't have any dashes or periods in them either.
              • 4. Re: parsing cgi.path_info
                Dinghus Level 1
                Is there a legitimate reason for NOT just going with the standard format of
                And so on?