« 1st C# App: Project Calculator | ^ Main | Jack the (_root) Hacker »
Using .ini Settings
On the AZCFUG list we were talking about loading settings from a .ini file or a database, pros vs cons. Without going in-depth I chose to go with the .ini file for security reasons. Below is the email I sent to the CFUG.
(look @ the code first)
I obviously could make the method receive the ini file dynamically but for my purposes this is fine. There is added functionality here that checks to see if the setting is private or not. I wanted to keep all settings in the ini so there wasn’t a mixture of straight app scope settings ( application.settings.blah = eek) and ini settings.
So, I did a lil’ something extra in my ini file.
[database]
private=1
dsn=site
[email]
private=0
server=localhost
info= info@email.com
error=myemail@email.com
[site]
private=0
title=Portal
domain=site.com
[security]
private=0
key=123sd1f32s1f2f
algorithm=CFMX_COMPAT
encoding=Base64
Basically it is normal except for the private=X. You can see in my method I check to make sure the section isn’t private. If it isn’t private I remove private (don’t need it in the app scope) from the list and add the rest to my struct then return the struct (which ultimately is stored in the app scope). This way I keep dsn out of the app scope but can also make other things private as needed.
<cffunction name="getSettings" access="public" output="false">
<cfset var ini = ExpandPath("assets/ini/") & " application.ini">
<cfset var settings = StructNew()>
<cfset var sections = GetProfileSections(ini)>
<cfset var tempList = "">
<cfoutput>
<cfloop collection="#sections#" item="i">
<cfif GetProfileString(ini, i, "private") EQ 0>
<cfset tempList = ListDeleteAt(sections[i], ListFindNoCase(sections[i], "private", ","), ",")>
<cfloop list="#tempList#" index="k">
<cfset settings[k] = GetProfileString(ini, i, k)>
</cfloop>
</cfif>
</cfloop>
</cfoutput>
<cfreturn settings>
</cffunction>
This seems to work great for me. Anyone have other thoughts/comments on how to better this setup?
Posted by John C. Bland II on January 23, 2006 1:51 AM | Permalink
TrackBack
TrackBack URL for this entry:
http://mt.katapultmedia.com/mt-tb.cgi/10



