Cookies

Contact Us or call 1-877-932-8228
Cookies

Cookies

Cookies are small text files that sit on the client machine. Web pages with the right permissions can read from and write to cookies. They are generally used to track user information between visits.

In ColdFusion, cookies are set with the <cfcookie> tag, which takes several attributes.

<cfcookie> Attributes
Attribute Description
name The cookie's name (required).
value The cookie's value.
expires The cookie's expiration date (if this isn't set, the cookie will expire when the browser window is closed).
secure A flag indicating whether the cookie should only be read over https.
path The directory path on the server that can read the cookie.
domain The domain name that can read the cookie.

The following code will set a cookie that expires in one week.

<cfcookie name="firstname" value="Paul" expires="7">

The following code will set a cookie that expires in on December 31, 2008.

<cfcookie name="firstname" value="Paul" expires="12/31/08">

The following code will set a cookie that never expires.

<cfcookie name="firstname" value="Paul" expires="never">

To delete a cookie, set the expiration date to now(), like this.

<cfcookie name="firstname" value="Paul" expires="now">
Next