Often, users disable cookies in their browsers. In this case, ColdFusion cannot maintain the client state automatically. You can use client or session variables without using cookies, by passing the client identification information between application pages. However, this technique has significant limitations, as follows:
Because the client's system does not retain any identification information, the next time the user logs on, ColdFusion cannot identify the user with the previous client and must create a new client ID for the user. Any information about the user from a previous session is not available, but remains in client data storage until ColdFusion deletes it. If you clear the Purge Data for Clients that Remain Unvisited option in the ColdFusion MX Administrator, ColdFusion never deletes this data.
Therefore, do not use client variables, if you allow users to disable cookies. To retain client information without cookies, require users to login with a unique ID. You can then save user-specific information in a database with the user's ID as a key.
Note: You can prevent ColdFusion from sending client information to the browser as cookies by setting This.setClientCookies variable in Application.cfc or the setClientCookies
attribute of the cfapplication
tag to No.
To use ColdFusion session variables without using cookies, each page must pass the CFID
and CFToken
values to any page that it calls as part of the request URL. If a page contains any HTML href
a=
links, cflocation
tags, form
tags, or cfform
tags the tags must pass the CFID
and CFToken
values in the tag URL. To use J2EE session management, you must pass the jsessionid
value in page requests. To use ColdFusion client variables and J2EE session variables, you must pass the CFID
, CFToken
, and jsessionid
values in URLs.
ColdFusion provides the URLSessionFormat
function, which does the following:
The URLSessionFormat
function automatically determines which identifiers are required, and sends only the required information. It also provides a more secure and robust method for supporting client identification than manually encoding the information in each URL, because it only sends the information that is required, when it is required, and it is easier to code.
To use the URLSessionFormat
function, enclose the request URL in the function. For example, the following cfform
tag posts a request to another page and sends the client identification, if required:
<cfform method="Post" action="#URLSessionFormat("MyActionPage.cfm")#>
Tip: If you use the same page URL in multiple URLSessionFormat
functions, you can gain a small performance improvement and simplify your code if you assign the formatted page URL to a variable, for example:
<cfset myEncodedURL=URLSessionFormat(MyActionPage.cfm)> <cfform method="Post" action="#myEncodedURL#">