• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 489
  • Last Modified:

How do I check the URL for a query string?

Hello Experts,

I know I've done this before but can't find any examples on my site or anyone else's. I need to be able to use a CFIF statement to see if there is a URL query string.
0
CementTruck
Asked:
CementTruck
  • 4
  • 3
1 Solution
 
_agx_Commented:
If you mean for the current URL, either check the cgi or URL scope:

<!--- using CGI variables --->
<cfif len(trim(CGI.QUERY_STRING))>has url params</cfif>

<!--- using URL scope --->
<cfif structCount(URL)>has url params</cfif>
0
 
sajaycCommented:
Hi,
If you know the URL variable you want to check for you can use this:

Example with prodid as url variable.

<cfif isdefined("url.prodid")>
  <cfset productid = url.prodid>
<cfelse>
  Do something else
</cfif>

Hope this helps.
0
 
_agx_Commented:
CementTruck - Are you trying to check for ANY query string parameters or for a specific parameter? My suggestion works for the former. For the latter, go with sajayc's suggestion. Though personally I prefer structKeyExists over isDefined.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
CementTruckAuthor Commented:
sajayc,

This is it. It works flawlessly. I could not remember "url.". What a brain fart.
0
 
CementTruckAuthor Commented:
@_agx_,

Your solution looks intriguing. I'll have to try and remember to figure out how it works.

Thank you!
0
 
_agx_Commented:
Well from the initial wording I thought you wanted to know if ANY parameters were passed, regardless of name. But ultimately that's not what you needed. So you can disregard it ;-)

sajayc's solution is the right one if you're trying to detect a specific parameter like: URL.ID or URL.page. Though again, I'd recommend structKeyExists over IsDefined. Either works but structKeyExists is preferred.

               <cfif structKeyExists(URL, "parameterName")>
                       found
               <cfelse>
                      not found
               </cfif>
0
 
CementTruckAuthor Commented:
@_agx_,

I will endeavor to delve into structKeyExist in the near future. Thanks for your dedication! You've always been a font of useful information.

Regards,
0
 
_agx_Commented:
Aww, thanks :) .. and you're very welcome!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now