• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

parsing cgi.path_info

New Here ,
Apr 03, 2008 Apr 03, 2008

Copy link to clipboard

Copied

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?
TOPICS
Advanced techniques

Views

438

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 03, 2008 Apr 03, 2008

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 03, 2008 Apr 03, 2008

Copy link to clipboard

Copied

quote:

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 03, 2008 Apr 03, 2008

Copy link to clipboard

Copied

Dan, I wasn't talking about a CF variable. I was talking about a variable in the form that jqcf is using.

/page.cfm/var1.valueofvar1-var2.valueofvar2-var3.valueofvar3

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

/page.cfm/my-var.valueofmyvar-var2.valueofvar2-var3.valueofvar3

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:
URL['my-var']

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 04, 2008 Apr 04, 2008

Copy link to clipboard

Copied

LATEST
Is there a legitimate reason for NOT just going with the standard format of
mypage.cfm?var1=valofvar1&var2=valofvar2
And so on?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation