Just include from or place this in the application.cfm file.
<!---
A handy timesaver:
Place this in your application.cfm file and you will always know the URL
and file path to the root of your application.
Advanced:
If for some reason, you need to reset, simply pass is "?flush=1" on any
site page
--->
<!--- START: Define Global Settings that should only be
set-up once --->
<cfif (NOT isdefined("APPLICATION.siteURL"))
OR isdefined("URL.flush")>
<!--- START: Lock so we can define all
application variables safely --->
<cflock scope="APPLICATION"
timeout="#CreateTimeSpan(0,0,0,500)#">
<cfset APPLICATION.siteURL =
replace(GetDirectoryFromPath("http://"&cgi.server_name&
cgi.path_info),"\","")>
<cfset APPLICATION.file_path =
GetDirectoryFromPath(GetCurrentTemplatePath())>
<!--- Place other
APPLICATION definitions here... --->
</cflock>
<!--- END: Lock so we can define all
application variables safely --->
</cfif>
<!--- END: Define Global Settings that should only be
set-up once --->
Just include from or place this in the application.cfm file.
This is a nice script, but I'm trying to run a slightly more advanced version. I am trying to determine output of a menu based on the subfolder that the page is contained within. However, this script stops once it reaches the root folder. Can you think of how it can determine the last folder to appear (or a more absolute path) and work off of that?
What if the first file pulled from the site is in a subfolder? I have an admin login area that gets a lot of hits ( more than the public side ), so there is a high likelyhood that by using this method, you could run into problems if you have cfm pages in multiple directories.
I already had errors and found it out the hard way. Be careful here, I am going back to simply calling the function at the time of use
Couldn't get the siteURL, it show empty, even replaced with cgi.script_name.
tried this out today with cfmx, where cgi.path_info returned only an empty string. After I replaced with cgi.path_info with cgi.script_name I got the correct siteURL