Jump to content
Sign in to follow this  
Skemcin

Application.cfm

Recommended Posts

The code will ensure that each client visit to the website gets a fresh session started. If all browser windows are closed than all sessions are ended - great for protecting your users from the famous phantom login - where Person A in the library closes all the browsers and walks away and then Person B comes right in opens the browser and is still logged in as Person A.

<!--- clearing session when browser closes ---><cfif ISDEFINED("cookie.CFID") and ISDEFINED("cookie.CFTOKEN")>	<cfset localCFID = Cookie.CFID>	<cfset localCFTOKEN = Cookie.CFTOKEN>	<cfcookie name="CFID" value="#localCFID#">	<cfcookie name="CFTOKEN" value="#localCFTOKEN#"></cfif>

Many times, I see a variable set to PRO or DEV and then a condition statement corresponding. This is irritating because when I move the Application.cfm file from development to production, I have to remember to change the variable from DEV to PROD. This code eliminates that step and ensures that the right code is always being processed for the right server since it sniffs out the actual box it is be processed on.

<!--- dynamically determine production vs development server ---><cfif #cgi.local_addr# IS "148.122.2.11">	<!--- live server --->	<cfset dirused="d:\websites\w3schools">	<cfset urlused="http://www.w3schools.com">	<cfset secureurl="https://www.w3schools.com">	<cfset session.mailserver="mail.w3schools.com">	<cfset webroot="/">	<cfset dsn="w3schools_prod">	<cfset uname="username">	<cfset pword="password"><cfelse>	<!--- dev server --->	<cfset dirused="s:\Inetpub\wwwroot\w3schools">	<cfset urlused="http://localhost/w3schools">	<cfset secureurl="http://localhost/w3schools">	<cfset session.mailserver="mail.w3schools.com">	<cfset webroot="/w3schools/">	<cfset dsn="w3schools_dev">	<cfset uname="username">	<cfset pword="password"></cfif>

Save the server some time. For global variable, don't set them on every page every single load. <cfparam> will assign a variable a value if the variable doesn't already exist. Wrapping this in a condition like this will only set the variables once and save the engine from processing the the information.

<!--- set global session variables ---><cfparam name="session.instantiated" default="0"><cfif session.instantiated EQ 0><cfparam name="session.xxxxxx" default=""><cfparam name="session.xxxxxx" default=""><cfparam name="session.xxxxxx" default=""><cfset session.instantiated=1></cfif>

Also, be sure to capitalize the letter A in Application.cfm. For windows servers its not that big of a deal, but anytime case sensitive file processing is turned on, this rule will need to be followed.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×