Coldfusion SESSION and COOKIE scope

Working with both SESSION and COOKIE scope tripped me up today so I wanted to illustrate what went wrong so hopefully others can avoid this.

Example 1:


This sets a session variable that will exist for the life of the session.

Example 2:


This sets a cookie that will exist for the life of the browser session.

Example 3:


This sets a cookie that will expire in 8 hours.

In my application.cfc I had set:

" />

I had incorrectly thought that this timespan would also apply to the COOKIE scope, but it does not.

Leave a Reply

Your email address will not be published. Required fields are marked *