Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing/testing for cookie 1

Status
Not open for further replies.

leadman

Programmer
Jun 11, 2001
177
US
Im trying to write a cookie to clients machines and then test for the existence of the cookie as a way of counting unique hits. Something is wrong but i cant tell what. Here's what i did. FIrst i check for the existence of the cookie and if its not there i increment the counter and write the cookie (here is the code):

<cfif not isdefined(&quot;Cookie.visitedsurvey&quot;)>
<cfquery name=&quot;updateUnique&quot;
datasource=&quot;mydb&quot;
dbtype=&quot;ODBC&quot;>
UPDATE counter
SET uniqueVisitors = (uniqueVisitors + 1)
WHERE page = 'survey'
</cfquery>
<cfcookie name=&quot;visitedsurvey&quot; value=&quot;&quot; expires=&quot;30&quot;>
</cfif>
</cflock>

for some reason, the uniqueVisitors field increments up every time i refresh the page. Anyone know why? (my browser does accept cookies)
 
Hi leadman,

Maybe you should give the cookie a value, not just an empty string? It could be that the cookie isn't written if it has no content.

Gtz,

Kristof -------------------
Check out my new site:

Any suggestions are more than welcome.
There's a LOT of work to do, so judge fairly. :)
 
Does it work if you physically delete the cookie, or set EXPIRES=&quot;NOW&quot;? Kevin
slanek@ssd.fsi.com
 
putting a value in didnt help. and the cookie soesnt seem tto have been written - cant find it. hmmm - and i thought writing a cookie would be easy....
 
Are you using <CFLOCATION> anywhere on the page? If so, <CFCOOKIE> will not be set. Kevin
slanek@ssd.fsi.com
 
no <cflocation> but the whole thing is in a <cflock> tag - does that matter?
 
Not sure. Only thing I can suggest is taking the <CFLOCK> out and giving it a try.

Also, try creating a blank page with only <CFCOOKIE> in it. Run the page and see if you have a cookie set then. At least then you'll know if the problem is with the cookie, or the other code in your page. Kevin
slanek@ssd.fsi.com
 
aha! it was the cflock the whole time - okay, thanks for the help
 
Cool. I've noticed there are certain things you just can't do when trying to set a cookie.

Glad it worked out. Kevin
slanek@ssd.fsi.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top