CFLib.org – Common Function Library Project

getCurrentURL()

Last updated September 5, 2008

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

 
Rated 2 time(s). Average Rating: 4.5

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:

view plain print about
<cfset pageURL = GetCurrentURL()>

Parameters:

No arguments.

Full UDF Source:

view plain print about
<!---
 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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
3 day(s) ago

Will Belden Will Belden added
longTime
9 day(s) ago

James Sleeman James Sleeman added
quickSort
19 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
22 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson