Save the current URL in to a variable using ColdFusion

Someone found one of my other pages looking for this, and here's how you do it:

#CGI.SCRIPT_NAME# will give you the path of the page and it's filename, e.g. "/coldfusion_articles/coldfusion_current_url.cfm" is the path of this web page.

#CGI.SERVER_NAME# gives you the name of the web server, e.g. "www.tenpastmidnight.com"

If you want to put it all together in to a variable, do it like this:

<CFSET CurrentURL = 'http://' & CGI.SERVER_NAME & CGI.SCRIPT_NAME>

Which in the case of this page is: "http://www.paulsilver.co.uk/code/coldfusion_current_url.php" (if this was a CF page rather than PHP.)

More code articles

Useful books
Cover of Mastering ColdFusion
Mastering ColdFusion MX
Amazon UK | USA
Cover of Programming ColdFusion MX
Programming ColdFusion MX
Amazon UK | USA
Cover of ColdFusion X Web Application Construction Kit
ColdFusion X Web Application Construction Kit
Amazon UK | USA

Paul Silver. November 2003


Silver Web Services Ltd

© 2014 Paul Silver