Using ColdFusion Server Variables

Most of you probably know that you can get a lot of information about your server environment from the implicit “server” variable scope, however what is not so obvious is why this information is useful. First of all, here is everything you can find out, and their values on my weblog server:

server.coldfusion.appserver #server.coldfusion.appserver#
server.coldfusion.expiration #server.coldfusion.expiration#
server.coldfusion.productlevel #server.coldfusion.productlevel#
server.coldfusion.productname #server.coldfusion.productname#
server.coldfusion.productversion #server.coldfusion.productversion#
server.coldfusion.rootdir (not available)
server.coldfusion.serialnumber (not available)
server.coldfusion.supportedlocales #server.coldfusion.supportedlocales#
server.os.additionalinformation #server.os.additionalinformation#
server.os.arch #server.os.arch#
server.os.buildnumber #server.os.buildnumber#
server.os.version #server.os.version#

Server variables are most often useful when your code needs to run in multiple environments, and you are not able to develop in a completely platform independent manner. For instance, you might need to to know what the server’s path separator is so that you can reference files on the file system. One way to get this information is from the variable, like this:

<cfset pathSep = iif( eq "UNIX",de("/"),de("\"))/>

You can also use the server.os.additionalinformation and server.os.version variables to determine if certain ColdFusion functionality (like Verity searches) are supported, or the server.coldfusion.productversion variable to make sure the user has installed your application with the right version of ColdFusion. If you are writing an application that you intend to distribute, and that can potentially be run on any platform that supports ColdFusion, a little platform validation can go a long way toward making installations more user friendly.

What other uses do people have for server variables?