dealing with cookies is in it's essence very simple; you will have to work through few examples and then you will be surprised; you will have to consider using cookies for shopping cart type application; there are a lot of users that will have cookies disabled, and in that case you will loose control over the application; I am using cookies only to recognize returning visitors (where possible), but for application management I will use client or session variables that are defined and stored on the ColdFusion server; tek-tips recognize you becouse the application is plantng cookie on your system; if you delete that cookie, next time you come back you will have to log in; after you log in, your old settings will kick in; that tells you that your acctual settings were not stored in the cookie you just erased, but rather in some other place (registry, or database);
try working with client variables and cookies will become clear by themselves;
when writing cfapplication you have to specify (among other things) setclientcookies and clientmanagement attributes:
<cfapplication
name="appName"
sessionmanagement="Yes"
sessiontimeout="#CreateTimeSpan(0, 0, 20, 0)#"
applicationtimeout="#CreateTimeSpan(1, 0, 0, 0)#"
setclientcookies="Yes"
clientmanagement="Yes">
to see exactly what is going on when you do that, try erasing all cookies on your system (check temporary internet files folder), and then make a requst for a template; you should see cookie writing it self in that folder
with that in working order, to create client variable, all you have to do is use regular expression:
<cfparam name="client.varName" default="someValue"> or
<cfset client.varName = someValue>
what happens now is harder to see, but you have just created client variable; it is stored in your registry (it is a default storage), and it will last for it's default of 90 days; if specified, you can use cookies or database to store client variable;
if possible you might want to try to work with databases (it has a lot of good aspects other then it's mobility); if you decide to work with database, after you specify data source in your ColdFusion administrator, after first request for a template, you will see two tables created automatically: CGLOBAL and CDATA;
CGLOBAL will store cfid, data and lvisit, and CDATA will store cfid, app and data; when client variable is created using cfparam or cfset, you will find the acctual variable and it's value in the data field of the CDATA table
- when you want to change the variable's value, you will simply use cfset;
- when working with shopping cart, to store temporary values (such as shopping cart content), you can use session variables
hope this will get you started Sylvano
dsylvano@hotmail.com
"every and each day when I learn something new is a small victory..."