I'm working on my final version of a script I've been working on for a week or so. I got everything working to my liking except the last one variable which is finalScriptPath which maps to my table columnscriptPath, which is to strip the page name out of the URL path so that a path like "www.example.com/products/2015/example.cfm will render just the "products\2015" folder structure. See included snip. Here is my code so far:
!---Function named EndRequestFunc for testing safely on CF Server--->
<!---Rename function to OnRequestStart and place in Application.cfm file before running live--->
<cffunction name="EndRequestFunc" access="public" returnType="string">
<!---Variable declared and set to empty--->
<cfset referer_path_and_file = "">
<cfset referer_path = "">
<cfset referer_file_name = "">
<cfset script_path_and_file = "">
<cfset script_path = "">
<cfset script_file_name = "">
<cfif cgi.HTTP_REFERER neq ''>
<!--- all of this will fail if there is no referer, for instance, if they bookmark the page --->
<!--- cgi.HTTP_REFERER may contain URL parameters, so let's strip those --->
<cfset referer_path_and_file = ListFirst(CGI.HTTP_REFERER, "?")>
<!--- now let's get just the path, stripping out the web server info --->
<cfset referer_path = ListDeleteAt(CGI.HTTP_REFERER, ListLen(CGI.HTTP_REFERER, "/"), "/")>
<cfset referer_path = ReplaceNoCase(referer_path, "https", "", "All")>
<cfset referer_path = ReplaceNoCase(referer_path, "http", "", "All")>
<cfset referer_path = ReplaceNoCase(referer_path, "://machine1.fss.com", "", "All")>
<cfset referer_path = ReplaceNoCase(referer_path, "://www_dev.fss.com", "", "All")>
<cfset referer_path = ReplaceNoCase(referer_path, "://www.fss.com", "", "All")>
<cfset referer_path = ReplaceNoCase(referer_path, "://10.11.2.60/", "", "All")>
<cfset referer_path = referer_path & "/">
<cfset referer_path = ReplaceNoCase(referer_path, "/", "\", "All")>
<!--- now let's remove everything but the file name --->
<cfset referer_file_name = ListLast(referer_path_and_file, "/")>
<!--- and that leaves us with these variables set --->
<!--- referer_path_and_file = "#referer_path_and_file#"<br />
referer_path = "#referer_path#"<br />
referer_file_name = "#referer_file_name#"<br />
<br />--->
</cfif>
<!--- cgi.SCRIPT_NAME does not include URL parameters --->
<cfset script_path_and_file = ListFirst(CGI.SCRIPT_NAME, "\")>
<!--- now let's get just the path, stripping out the web server info --->
<cfset script_path = GetDirectoryFromPath(GetCurrentTemplatePath())>
<cfset script_path = ReplaceNoCase(script_path, "C:\inetpub\wwwroot\Clients\fss.com\www_dev", "", "All")>
<cfset script_path = ReplaceNoCase(script_path, "C:\inetpub\wwwroot\Clients\fss.com\www", "", "All")>
<!--- now let's remove everything but the file name --->
<cfset script_file_name = ListLast(script_path_and_file, "/")>
<!--- and that leaves us with these variables set--->
<!---script_path_and_file = "#script_path_and_file#"<br />
script_path = "#script_path#"<br />
script_file_name = "#script_file_name#"<br />--->
<!---<!---CFC Test Query--->
<cfquery name="qryTest" datasource="Fss_Dev" >
INSERT INTO tblCFMPageRequest(pageName)
VALUES
('MyPage.cfm')
</cfquery>--->
<!---Directory Stripping And Modifier Block Goes Here--->
<!---Set CGI System Variables--->
<cfset currentHeader = CGI.HTTP_REFERER >
<cfset currentScriptPage = CGI.SCRIPT_NAME >
<!---Set currentScriptPage as command line directory string and delcare new variable "reverseScriptPage"--->
<cfset reverseScriptPage = ReReplace(#currentScriptPage#, "/", "\","ALL")>
<!---Set reverseScriptPage value as newly format command line directory structure--->
<cfset newScriptPage = ListSetAt(#reverseScriptPage#, 1, "#reverseScriptPage#") >
<cfset lastScriptPage = ListFirst(#newScriptPage#, "/") > <!---Added this 5/11/2015--->
<cfset finalScriptPage = ListSetAt(#lastScriptPage#, 1, "#lastScriptPage#") >
<cfset finalScriptPath = ReReplace(#finalScriptPage#, "/", "\","ALL") >
<!---CGI.HTTP_HEADER Formatting Block--->
<!---This block retrieves the http header value, then strips http formatting--->
<!---currentHeader variable truncated by ListLast then assigned to variable headerFileName--->
<cfset headerFileName = ListLast(#currentHeader#,"/")>
<!---currentHeader URL string has "/" replaced with "\" characters then set as variable reverseHeaderURL--->
<cfset reverseHeaderURL = ReReplace(#currentHeader#, "/", "\","ALL")>
<!---reverseHeaderURL is stripped of all known http type formattings and IP formattings--->
<cfif cgi.HTTP_REFERER neq ''>
<cfset reverseHeaderURL = ListDeleteAt(cgi.HTTP_REFERER, ListLen(cgi.HTTP_REFERER, "/"), "/")>
<cfset reverseHeaderURL = ReplaceNoCase(reverseHeaderURL, "https", "", "All")>
<cfset reverseHeaderURL = ReplaceNoCase(reverseHeaderURL, "http", "", "All")>
<cfset reverseHeaderURL = ReplaceNoCase(reverseHeaderURL, "://machine1.fss.com", "", "All")>
<cfset reverseHeaderURL = ReplaceNoCase(reverseHeaderURL, "://www_dev.fss.com", "", "All")>
<cfset reverseHeaderURL = ReplaceNoCase(reverseHeaderURL, "://www.fss.com", "", "All") >
<cfset reverseHeaderURL = ReplaceNoCase(reverseHeaderURL, "://machine1.fss.com", "", "All")>
<cfset reverseHeaderURL = ReplaceNoCase(reverseHeaderURL, "://10.11.2.60/", "", "All")>
<cfset reverseHeaderURL = ReplaceNoCase(reverseHeaderURL, ":\\dev.fss.com\", "", "All")> <!---Added this line 5/11/2015--->
<!---The end result is then formatted to C:\\ command line format and stored in new variable newHeaderURL--->
<cfset newHeaderURL = ListSetAt(#reverseHeaderURL#, 1, "#reverseHeaderURL#") >
<cfset finalHeaderURL = ReReplace(#newHeaderURL#, "/", "\","ALL")>
</cfif>
<!---Queries Table To Get Requested Record--->
<cfquery name="qryGetPageRecord" datasource="Fss_Dev" dbname="Fss_Dev">
SELECT referrerPage
FROM tblCFMPageRequest
WHERE referrerPage = '#referer_file_name#' AND scriptName = '#script_file_name#'
</cfquery>
<!---Conditional Check for record count equal to 0--->
<cfif qryGetPageRecord.recordCount eq 0>
<!---<cfset httpReferer = ListLast('http://www.fss.com/index.cfm?uid=testValue',"/")>
<cfset ListFirst(httpReferer,"?")>--->
<!---variable declared as scriptName and set equal to CGI.SCRIPT_NAME --->
<!---Value truncated to actual file name through function ListLast() --->
<cfquery name="setNewRecord" datasource="Fss_Dev" dbname="Fss_Dev">
INSERT INTO tblCFMPageRequest (referrerPage, referrerPath, scriptName, scriptPath)
VALUES (<cfqueryparam cfsqltype="cf_sql_varchar" value="#referer_file_name#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#finalHeaderURL#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#script_file_name#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#finalScriptPath#">)
</cfquery>
</cfif>
</cffunction>
Found my solution after some trial and error working with a code block in particular. Below is the solution that worked to strip out the file name, leaving only the path.
<cfif cgi.PATH_INFO neq ''>
<cfset script_path_and_file = ListFirst(CGI.PATH_INFO, "?")>
<cfset script_path = ListDeleteAt(CGI.PATH_INFO, ListLen(CGI.PATH_INFO, "/"), "/")>
<cfset script_path = ReplaceNoCase(script_path, "https", "", "All")>
<cfset script_path = ReplaceNoCase(script_path, "http", "", "All")>
<cfset script_path = ReplaceNoCase(script_path, "://machine1.fss.com", "", "All")>
<cfset script_path = ReplaceNoCase(script_path, "://www_dev.fss.com", "", "All")>
<cfset script_path = ReplaceNoCase(script_path, "://www.fss.com", "", "All")>
<cfset script_path = ReplaceNoCase(script_path, "://10.11.2.60/", "", "All")>
<cfset script_path = script_path & "/">
<cfset script_path = ReplaceNoCase(script_path, "/", "\", "All")>
<cfset script_file_name = ListLast(script_path_and_file, "/") >
</cfif>
<cfset script_path = GetDirectoryFromPath(GetCurrentTemplatePath())>
<cfset script_path = ReplaceNoCase(script_path, "C:\inetpub\wwwroot\Clients\fss.com\www_dev", "", "All")>
<cfset script_path = ReplaceNoCase(script_path, "C:\inetpub\wwwroot\Clients\fss.com\www", "", "All")>
<cfset script_path = ReplaceNoCase(script_path, "C:\inetpub\wwwroot\", "", "All")>
<cfset script_file_name = ListLast(script_path_and_file, "/")>
<cfquery name="setNewRecord" datasource="Fss_Main_Dev" dbname="Fss_Dev">
INSERT INTO tblCFMPageRequest (referrerPage, referrerPath, scriptName, scriptPath)
VALUES (<cfqueryparam cfsqltype="cf_sql_varchar" value="#referer_file_name#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#finalHeaderURL#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#script_file_name#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#script_path#">)
</cfquery>
</cffunction>