I have a site which lets users login on any page using a simple login box at the top of the screen.
This login box has a form with a username and password field. It sends the login details to a CFC which does the backend validation stuff and then redirects the user to the page they were on.
Normally, you would use something like <cfset SESSION.OriginalURL = CGI.ScriptName/>
to set the original URL and then use that variable in the CFC. But my site uses URL rewriting to make nice clean URLs. I want the user to be taken back to the clean URL e.g. mysite.com/shopping/computers
What I need to do is get the display URL that is in the address bar of the browser rather than the true ugly URL. To do this, I can use <cfset SESSION.OriginalURL = StructFind(GetHttpRequestData().headers, 'X-Original-URL')/>
The problem is that the above method does not work on certain pages (basically pages that don't have query string variables). See my question here Why does HttpHeader X-Original-URL not exist on some pages?
What would be the best way to store the clean/rewritten URL and pass it to the CFC as part of the login procedure?
You can test for the length of the value of X-Original-URL
and use it if it has a value, else use CGI.ScriptName
like:
<cfif StructKeyExists(GetHttpRequestData().headers, 'X-Original-URL')>
<cfset SESSION.OriginalURL = StructFind(GetHttpRequestData().headers, 'X-Original-URL')/>
<cfelse>
<cfset SESSION.OriginalURL = CGI.ScriptName/>
</cfif>