I knew this - but forgot and instead of spinning my wheels when I make the same mistake in a month, I figured I'd quickly blog it to help me remember.
Don't forget when you cfdump the CGI scope, you are getting what is basically a "known" set of CGI variables. There may be additional CGI values available that will not show up.
A good example of this is CGI.redirect_url. When using Apache URL rewriting, that value will contain the original request URL. So if you rewrite foo.cfm to goo.cfm, you can use cgi.redirect_url to return foo.cfm.
Archived Comments
It there any way, or list to see what the complete list is? Or is it all trial and error?
I'm guessing the CGI scope comes from the web server,so would that be where I'd look to see what information it makes available?
I found the same thing, but with ISAPI_Rewrite instead of Apache rewriting. The only difference is that the useful URL is CGI.HTTP_X_REWRITE_URL.
I wrote a post about it a while back:
http://sebduggan.com/posts/...
@Tim: I don't know. You would think it would be available via Java (remember you can get the low level page object via getPageContext()), but I'm not seeing any method that gets everything.
One that is pretty important for me with one client who is has clustered and load balanced servers.
CGI.X_FORWARDED_FOR
This gives us the correct remote_addr value instead of the network IP (10.10.16.10).
Jaana
So, you can USE a variable in the CGI scope that isn't showing up in cfdump? That's odd - if you can use, I would bet it should appear in the dump!
Maybe looping through the CGI collection instead of dumping?
This will definitely come in handy as very soon need to do quite a bit of 301 RegEx work on a CF 8 site ...
:-)
@Fernando - my understanding is that the CGI scope you see in the dump (and looping over the collection won't change it - that's what cfdump does under the covers) is based on a set of known common CGI vars.
"Known" and "common" as in "CGI vars that surely exists among environments", isn't it?
Now I remember reading something about it in the past (about 4-5 years ago), in some studies I did, probably before trying (and passing) my CF6 certification exam... makes sense.
Yeah. I think I've blogged on this before too. You can also output ANY cgi variable, like cgi.ray. We just output an empty string if there is nothing there.
And for those on IIS7, you can get the original request from CGI.HTTP_X_ORIGINAL_URL.
Ex:
[!--- IIS7 ---]
[cfif CGI.HTTP_X_ORIGINAL_URL neq '']
[cfset request.urlStrings= listToArray(spanExcluding(CGI.HTTP_X_ORIGINAL_URL, '?'), '/')]
[/cfif]
Forgot to mention... if you wanted to make your app more portable, do this:
[!--- IIS7 ---]
[cfif CGI.HTTP_X_ORIGINAL_URL neq '']
[cfset request.urlStrings= listToArray(spanExcluding(CGI.HTTP_X_ORIGINAL_URL,"?"), "/")]
[/cfif]
[!--- ISAPI_rewrite ---]
[cfif CGI.HTTP_X_REWRITE_URL neq '']
[cfset request.urlStrings= listToArray(spanExcluding(CGI.HTTP_X_REWRITE_URL ,"?"), "/")]
[/cfif]
[!--- APACHE ---]
[cfif CGI.REDIRECT_URL neq '']
[cfset request.urlStrings= listToArray(spanExcluding(CGI.REDIRECT_URL ,"?"), "/")]
[/cfif]
Given the mutually exclusive nature of these (?!) plus the fact that referencing non-existent CGI vars returns an empty string (and exchanging commentary for brevity), the above could just be...
<cfset request.urlStrings= listToArray(spanExcluding(CGI.HTTP_X_ORIGINAL_URL & CGI.HTTP_X_REWRITE_URL & CGI.REDIRECT_URL,"?"), "/")
/>
If you have one of the older WACK books, there used to be a reference in the back that contained a pretty good list of common, though not neccessarily available everywhere CGI variables. I found it in Appendix D and D.2 in the MX WACK (Sorry Ray)
Remember - every time you don't buy the latest WACK, I can't afford a new video game.
And I cry.
A lot.
I do buy the latest WACK, but I keep the old ones too, otherwise my bookshelves don't look like I have been coding CF for as long as I have <grin>; and besides, you don't need book income any more, you are getting rich building Nook apps now and those don't take near as long to write as a book does..