CFLib.org – Common Function Library Project

getCurrentURL()

Last updated September 5, 2008
Download UDF

author

Topper Topper

Version: 1 | Requires: ColdFusion MX | Library: UtilityLib

 
Rated 0 time(s). Average Rating: 0

Description:
Returns the current URL for the page. Works better than other methods. Other methods of calculating the URL from CGI variables won't work if your application is in a sub-folder like http://localhost/myapp/ - they ignore the "myapp" bit. I've seen and tired all sorts of other ways to get the Current URL but this is the only method I have found that works in all secenarios.

Return Values:
Returns a string.

Example:

<cfset pageURL = GetCurrentURL()>

Parameters:

No arguments.

Full UDF Source:

<!---
Returns the current URL for the page.

@return Returns a string.
@author Topper (topper@cftopper.com)
@version 1, September 5, 2008
--->

<cffunction name="getCurrentURL" output="No" access="public" returnType="string">
    <cfset var theURL = getPageContext().getRequest().GetRequestUrl().toString()>
    <cfif len( CGI.query_string )><cfset theURL = theURL & "?" & CGI.query_string></cfif>
    <cfreturn theURL>
</cffunction>

Search CFLib.org


Latest Additions

John Bartlett John Bartlett added
browserDetect
5 day(s) ago

Rob Brooks-Bilson Rob Brooks-Bilson added
listCompare
8 day(s) ago

Stephen Withington Stephen Withington added
formToNameValueP...
16 day(s) ago

anthony petruzzi anthony petruzzi added
parseExcel
21 day(s) ago

Pablo Varando Pablo Varando added
returnRandomHEXC...
22 day(s) ago

Top Rated

Nathan Dintenfass                                 QueryStringChang...
Rated 5.0, 10 time(s)

Stephen Withington formToNameValueP...
Rated 5.0, 5 time(s)

Gyrus                                             HTMLSafe
Rated 5.0, 4 time(s)

Shlomy Gantz                                      viewCSS
Rated 5.0, 4 time(s)

Michael Sharman generateRandomKe...
Rated 5.0, 3 time(s)

Created by Raymond Camden / Design by Justin Johnson