Tuesday, January 8, 2013

ColdFusion 10's CGI PATH_INFO Variable is Empty

A couple years ago I wrote a web app using ColdFusion 8 development server. I had wrote a method that I used to store the page name and query string of the current page into a session variable called "returnPage". I recently upgraded my developent server to ColdFusion 10 and I noticed my "returnPage" session variable was never being populated with any text. Doing some investigating, I discovered that the CGI variable named PATH_INFO (which in ColdFusion 8 stored the page name) is an empty string in ColdFusion 10. Doing a quick Google search, appears other's have ran into this same issue and reported it as a bug with ColdFusion 10. For the workaround, I chose to use ColdFusion's function GetFileFromPath() and passed in the CGI variable CF_TEMPLATE_PATH. Now the session variable "returnPage" contains the desired page name. Below is the old code and modified code:

Old Code:


<cfcomponent>

   <cffunction name="setReturnPage">

      <!--- This function sets the session variable returnPage to the current URL address --->

      <cfif cgi.QUERY_STRING IS NOT "">
         <cfset session.returnPage = "#cgi.PATH_INFO#" & "?" & "#cgi.QUERY_STRING#" >
      <cfelse>
         <cfset session.returnPage = "#cgi.PATH_INFO#">
      </cfif>

   </cffunction>

</cfcomponent>
Updated Code:

<cfcomponent>

   <cffunction name="setReturnPage">

      <!--- This function sets the session variable returnPage to the current URL address --->

      <cfif cgi.QUERY_STRING IS NOT "">
         <cfset session.returnPage = "#GetFileFromPath(cgi.CF_TEMPLATE_PATH)#" & "?" & "#cgi.QUERY_STRING#" >
      <cfelse>
         <cfset session.returnPage = "#GetFileFromPath(CF_TEMPLATE_PATH)#">
      </cfif>

   </cffunction>

</cfcomponent>

No comments: