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.
CementTruckAsked:
Who is Participating?
 
sajaycConnect With a Mentor Commented:
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:
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
 
_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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.