Defines web browser cookie variables, including expiration and security options.
Forms tags, Variable manipulation tags
<cfcookie name = "cookie_name" value = "text" expires = "period" secure = "Yes" or "No" path = "url" domain = ".domain">
cfdump, cfparam, cfregistry, cfsavecontent, cfschedule, cfset
If this tag specifies that a cookie is to be saved beyond the current browser session, ColdFusion writes or updates the cookie to the cookies.txt file. Until the browser is closed, the cookie resides in memory. If the expires attribute is not specified, the cookie is written to the cookies.txt file.
If you use this tag after the cfflush tag on a page, ColdFusion throws an error.
To set cookies and execute a redirect in the same page, use the cfheader tag to specify the new target URL; for example:
<cfheader name="location" value="OtherPage.cfm?foo=bar"> <cfheader statusCode="302" statusText="Document Moved"> <cfabort>
You can use dots in names within the cookie and client variable scopes, as the following examples show:
<cfcookie name="person.name" value="wilson, john"> <cfset cookie.person.lastname="Santiago"> <cfcookie name="a.b.c" value="a value"> <cfset client.foo.bar="a_value">
Caution: Do not set a cookie variable on the same page on which you use the cflocation tag. If you do, the cookie is never saved on the browser.
<!--- This example shows how to set/delete a cfcookie variable --->
<!--- Select users who have entered comments into sample database --->
<cfquery name = "GetAolUser" dataSource = "cfsnippets">
SELECT EMail, FromUser, Subject, Posted
FROM Comments
</cfquery>
<html>
<body>
<h3>cfcookie Example</h3>
<!--- if the URL variable delcookie exists, set cookie expiration date to NOW --->
<cfif IsDefined("url.delcookie") is True>
<cfcookie name = "TimeVisited"
value = "#Now()#"
expires = "NOW">
<cfelse>
<!--- Otherwise, loop through list of visitors; stop when you match
the string aol.com in a visitor's e-mail address --->
<cfloop query = "GetAolUser">
<cfif FindNoCase("aol.com", Email, 1) is not 0>
<cfcookie name = "LastAOLVisitor"
value = "#Email#"
expires = "NOW" >
</cfif>
</cfloop>
<!--- If the timeVisited cookie is not set, set a value --->
<cfif IsDefined("Cookie.TimeVisited") is False>
<cfcookie name = "TimeVisited"
value = "#Now()#"
expires = "10">
</cfif>
</cfif>
<!--- show the most recent cookie set --->
<cfif IsDefined("Cookie.LastAOLVisitor") is "True">
<p>The last AOL visitor to view this site was
<cfoutput>#Cookie.LastAOLVisitor#</cfoutput>, on
<cfoutput>#DateFormat(COOKIE.TimeVisited)#</cfoutput>
<!--- use this link to reset the cookies --->
<p><a href = "cfcookie.cfm?delcookie = yes">Hide my tracks</A>
<cfelse>
<p>No AOL Visitors have viewed the site lately.
</cfif>
ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting
Version 6
Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/Tags-pt119.htm
Comments
anandasim said on Jun 23, 2002 at 9:38 PM : h2oman said on Jun 27, 2002 at 5:26 PM : ctina said on Jul 11, 2002 at 8:14 PM : ctina said on Jul 19, 2002 at 7:19 PM : sgilson102 said on Aug 12, 2002 at 9:26 PM : wickedXen said on Jan 13, 2003 at 3:20 AM : wickedXen said on Jan 13, 2003 at 3:24 AM : spage-mm said on May 2, 2003 at 2:53 AM : No screen name said on Aug 4, 2004 at 12:22 PM : sdwebguy99 said on Oct 29, 2004 at 4:09 PM : istvanb said on Jan 22, 2006 at 8:11 PM :