Copy link to clipboard
Copied
i am going to make a "tracking" script for a website. my idea is to add a <CFINCLUDE> to every .cfm file on the server (right at the end, so it would be easier to remove when im done), and have the script that is included add a record to a database that contains the file name/path of the .cfm file. for example, index.cfm will include trackscript.cfm, and after the index.cfm is processed, a database will have a record in it containing the file name/path for index.cfm.
i am new to coldfusion, but i think i have everything figured out, except how to get the name of the file that will be added to the database. is there some kind of function or variable available that will give me the filename of the currently executing .cfm file?
GetCurrentTemplatePath() will give you the absolute path of the current CFM file.
Copy link to clipboard
Copied
I don't think sticking a <cfinclude> call into every file is really a very good way of doing this.
You should have a look at using onRequestEnd() for this sort of thing.
There are various variables in the CGI scope which one can use to build the originating URL of the current request; CGI.script_name and CGI.query_string are probably the most helpful here. One can resolve the underlying file system path form a URL using expandPath().
--
Adam
Copy link to clipboard
Copied
i was thinking about using a cfinclude because i could just write one script, and just link to that script from each file (keeping everything cleaner), rather than inserting all of the code into each individual file.
something i should point out: i'm not needing this as a tracking system to be used daily on the site. we have an expansive site, and over time, there are a lot of files sitting on the server that we don't need (like temporary edits and whatnot). so, i was thinking that if i made a quick tracking script to log which pages are actually accessed, and then use something like a website downloader (an app for offline browsing), the tracking script would give us a pretty good idea of what files are actually used, and then what files cannot even be accessed via normal browsing of the site.
Copy link to clipboard
Copied
Yep, I understand what you're trying to do, but I don't think it's a very good approach.
Have a look at how the debugging service can give you access to all the templates used in a request - in one fell swoop - by looking @ the code in [coldfusion context root]/WEB-INF/debug/classic.cfm.
You could either use that technique in onRequestEnd(), or perhaps better now that I think about it, just modify your debug template to write the list of templates to your DB.
--
Adam
Copy link to clipboard
Copied
GetCurrentTemplatePath() will give you the absolute path of the current CFM file.