Not yet rated
Tags:



Problem

Having multiple projects with the same application name can cause corrupt data and even security concerns. You tend to see this more in shared hosting environments but it can happen when you copy Application.cfm/.cfc from project to project.

Solution

You can hash() the current template path which will return you an unique identifier that can be used.

Detailed explanation

<cfset appHash = hash (getCurrentTemplatePath ()) />
<cfset appName = "myApp_" & appHash />
<cfset appName = left(appName, 64) />
<cfapplication name = "#appName#" sessionmanagement = "true" />

The left() command in the 3rd cfset just makes sure we don't exceed the max length an application name can be. Of course you can combine the first three lines to one single line:

 

<cfset appName = left ( "myApp_" & hash (getCurrentTemplatePath ()), 64 ) />
<cfapplication  name = "#appName#"  sessionmanagement = "true"  />

 


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes