On 2/9/01, [EMAIL PROTECTED] penned:
>Hi all,
>Despite having used CF for 2 years, only know am I venturing into using
>CFCOOKIE. I have a couple of questions:
>
>- How can I make sure the browser has cookies enabled?

You need to enable session or client management, then check for the 
existence of the session or client variable. Actually, I believe 
client management needs to be on anyway to set cfid and cftoken.

<cfif not isdefined('client.rollcount')>

<cfset client.rollcount = 1>
<cfcookie name="mytestcookie" value="On" expires="1">
<cfset variables.id = "cfid=" & client.cfid & "&cftoken=" & client.cftoken>

<cfelse>

     <cfif isdefined('cookie.mytestcookie')>
     <cfset variables.id = "">
     <cfelse>
     <cfset variables.id = "cfid=" & client.cfid & "&cftoken=" & client.cftoken>
         <cfif client.rollcout is 1>
         <cfset client.rollcount = 2>
         <cfset variables.nocookies = 1>
         </cfif>
     </cfif>

</cfif>

You will need to add ?#variables.id# to the end of your links. Upon 
entering the site the program will try to set a cookie, set 
client.rollcount (or session.rollcount if you'd rather use that) to 1 
and the cfid and cftoken will be appended to any links. Upon the 
first click, client.rollcount will be 1 so now the program will test 
to see if cookie.mytestcookie exists. If it does, we can pass the 
cfid and cftoken the rest of the way to keep the session alive and 
cookies aren't needed. We can also now look for the existence of 
variables.nocookies and give the user a message like "You have 
cookies disabled. While this will work fine, if you leave our site 
for any reason, the items in your shopping cart will be removed". 
Then we set client.rollcount to 2 so variables.nocookies isn't set on 
subsequent clicks and they only get that message once.

>- How much can I store in them?

I think it's 4 KB. Enough for most cookie uses, but not enough to 
store the contents of a shopping cart or something.

>- Presumably I can encrypt / decrypt the contents?

Yeah. Just set the value with the encrypt() function first.

>- Any pitfalls I should look out for (other than CFLOCATION on the same
>page)...

Not really. Just remember you CAN'T check for the existence of a 
cookie on a page below where you've set it. Even if cookies are 
turned off, once you set it it will exist for that instant as far as 
CF is concerned. Just like a local variable except it won't be stored 
on the users computer.
-- 

Bud Schneehagen - Tropical Web Creations

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
ColdFusion Solutions / eCommerce Development
[EMAIL PROTECTED]
http://www.twcreations.com/
954.721.3452

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to