# CFAPPLICATION

Defines scoping for a ColdFusion application, enables or disables storing client variables, and specifies a client variable storage mechanism. By default, client variables are disabled. Also, used to enable session variables and to set timeouts for both session and application variables. Session and application variables are stored in memory.

### Syntax

    <CFAPPLICATION NAME="Name"
        CLIENTMANAGEMENT="Yes/No"
        CLIENTSTORAGE="Storage Type"
        SETCLIENTCOOKIES="Yes/No"
        SESSIONMANAGEMENT="Yes/No"
        SESSIONTIMEOUT=#CreateTimeSpan(days, hours,
          minutes, seconds)#
        APPLICATIONTIMEOUT=#CreateTimeSpan(days, hours,
          minutes, seconds)#
        SETDOMAINCOOKIES="Yes/No"
    >

#### NAME

The name you want to give your application. This name can be up to 64 characters long. Required for application and session variables to work. Optional for client variables.

#### CLIENTMANAGEMENT

Optional. Yes or No. Enables client variables. Default is No.

#### CLIENTSTORAGE

Optional. Specifies the mechanism for storing client variables:

- datasourcename -- ColdFusion stores client variables in the specified ODBC or native data source. To use this option you must create a client variable storage repository using the Variables page of the ColdFusion Administrator.
- Registry -- ColdFusion stores client variables in the system registry. This is the default.
- Cookie -- ColdFusion stores client variables on the client machine in a cookie. Storing client data in a cookie is scalable to large numbers of clients, but this storage mechanism has some limitations. Chief among them is that if the client turns off cookies in the browser, client variables won't work.

#### SETCLIENTCOOKIES

Optional. Yes or No. Yes enables client cookies. Default is Yes.

If you set this attribute to "NO", ColdFusion does not automatically send the CFID and CFTOKEN cookies to the client browser; you must manually code CFID and CFTOKEN on the URL for every page that uses Session or Client variables.

#### SESSIONMANAGEMENT

Optional. Yes or No. Yes enables session variables. Default is No.

#### SESSIONTIMEOUT

Optional. Enter the CreateTimeSpan function and the values you want in days, hours, minutes, and seconds, separated by commas to specify the lifespan of any session variables that are set. The default value is specified in the Variables page of the ColdFusion Administrator.

#### APPLICATIONTIMEOUT

Optional. Enter the CreateTimeSpan function and the values you want in days, hours, minutes, and seconds, separated by commas to specify the lifespan of any application variables that are set. The default value is specified in the Variables page of the ColdFusion Administrator.

#### SETDOMAINCOOKIES

Optional. Yes or No. Sets the CFID and CFTOKEN cookies for an entire domain not just a single host. Applications that are running on clusters must set this value to Yes. The default is No.

### Usage

CFAPPLICATION is typically used in the `Application.cfm` file to set defaults for a specific ColdFusion application.

CFAPPLICATION enables application variables unless they have been disabled in the ColdFusion Administrator. Using the SESSIONMANAGEMENT attribute to enable session variables is also overridden by the Administrator. See Administering ColdFusion Server for information about the ColdFusion Administrator.

Server, Application, and Session Variables

Whenever you display, set, or update variables in the server, application, and session scopes, you should use the CFLOCK tag with the SCOPE attribute. For server variables, specify the "Server" scope. For application variables, specify the "Application" scope. For session variables, specify the "Session" scope. See CFLOCK for information about locking server, application, and session scopes.

If you are running ColdFusion on a cluster, you must specify either Cookie or a data source name for CLIENTSTORAGE; you cannot specify Registry.

### Example

    <!-------------------------------------------------------------
        This example shows how CFLOCK can be used to guarantee the
        consistency of data updates to variables in the Application,
        Server, and Session scopes.
        You should copy the following code into an Application.cfm
        file in the snippets directory.
    --------------------------------------------------------------->
        <HTML>
        <HEAD>
            <title>Define Session and Application Variables</title>
        </HEAD>

        <BASEFONT FACE="Arial, Helvetica" SIZE=2>
        <BODY  bgcolor="#FFFFD5">

        <H3>CFAPPLICATION Example</H3>

        <P>CFAPPLICATION defines scoping for a ColdFusion application and
        enables or disables the storing of application and/or session
        variables. This tag is placed in a special file called
        Application.cfm that is run before any other CF template in a
        directory where the Application.cfm file appears.

        <CFAPPLICATION NAME="ETurtle" SESSIONTIMEOUT=#CreateTimeSpan(0, 0,
          0, 60)# SESSIONMANAGEMENT="yes">
        <!-------------------------------------------------------------
        Initialize the session and application variables that will be
        used by E-Turtleneck. Use the session scope for the session
        variables.
        --------------------------------------------------------------->
        <CFLOCK SCOPE="Session" TIMEOUT="30" TYPE="Exclusive">
            <CFIF NOT IsDefined("session.size")>
                <CFSET session.size = "">
            </CFIF>
            <CFIF NOT IsDefined("session.color")>
                <CFSET session.color = "">
            </CFIF>
        </CFLOCK>

        <!----------------------------------------------------------------
        Use the application scope for the application variable. This
        variable keeps track of the total number of turtlenecks sold.
        ------------------------------------------------------------------->
        <CFLOCK SCOPE="Application" TIMEOUT="30" TYPE="Exclusive">
            <CFIF NOT IsDefined("application.number")>
                <CFSET application.number = 1>
            </CFIF>
        </CFLOCK>
        <CFLOCK SCOPE="Application" TIMEOUT="30" TYPE="ReadOnly">
            <CFOUTPUT>
            E-Turtleneck is proud to say that we have sold
            #application.number# turtlenecks to date.
            </CFOUTPUT>
        </CFLOCK>
    <!--- End of Application.cfm --->