O'Reilly logo

Adobe ColdFusion 8 Web Application Construction Kit, Volume 1: Getting Started by Charlie Arehart, Raymond Camden, Ben Forta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Cookies

You can easily build on the last example to make it more useful in the real world. For instance, you wouldn’t want the Time Started value to be reset every time the user visited the first page; you probably want the value to be recorded only the first time. So it would make sense to first test for the cookie’s existence and only set the cookie if it doesn’t already exist. It would also make sense to remember the full date/time value of the user’s first visit, rather than just the time.

So, instead of

<cfset COOKIE.TimeVisitStart = timeFormat(now(), "h:mm:ss tt")>

you could use

<cfif not isDefined("COOKIE.VisitStart")>
 <cfset COOKIE.VisitStart = now()>
</cfif>

In fact, the isDefined test and the <cfset> tag can be replaced with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required