Skip to main content
November 27, 2012
Answered

cfcookie expires immediately

  • November 27, 2012
  • 2 replies
  • 4946 views

I cannot get cfcookie to stop expiring immediately.  It worked fine until recently switching to a new VPS.  Now the cookies only get set the first time Application.cfm is run.  If you visit any other page in that same director the cookie mysteriously disappears.

Here is my application tag...

<cfapplication name="KYND" sessionmanagement="yes" sessiontimeout="#CreateTimeSpan(0,3,0,0)#" setclientcookies="no" setdomaincookies="yes">

http://www.kyndoutdoors.com/dbf/_kynd-controller/my-kynd.cfm

Use timmyv as both the username and password.

This topic has been closed for replies.
Correct answer 12Robots

Because of what happens to me when I test it.  If you look at the code, it says "if the cookie is not blank, display all is well in cookie world".  I get that message the first time I login, but then when I click either of the links at the bottom, the cookie is no longer present and I get the login form.  That is the root of this entire issue.  The cookie gets set once, but then visit any other page and its gone.


Your cookies are NOT being deleted. The problem is the duplication. And more specifically, the problem is that cfparam that I encouraged you to remove.

Your first decision in your test is this:

<cfif #cookie.kp_id# EQ "">      (btw, you don't need hash marks in this code or in any of the other cfif statements in your code. Please remove them, they are soooo ugly)

Well, kp_id is both blank and it's not. The cookie exists twice, once with and once without a value. CF is using the one without a value. Both are being sent, whatever order they are being sent in results in the cookie being blank.

Here is the HTTP request being sent:

GET /dbf/cookies.cfm HTTP/1.1

Host: www.kyndoutdoors.com

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-US,en;q=0.5

Accept-Encoding: gzip, deflate

Connection: keep-alive

Cookie: kp_id=""; KP_ID=13608; KP_USERNAME=timmyv; KP_PASSWORD=timmyv

The important line is the last one. TWO KP_IDs are being sent. One is blank, one is not. CF must use the first one it recieves.

Regardless, remove the cfparam (you'll need to add a check for existence to your cfifs that make use of that cookie var), delete your cookies and try it again.

Jason

2 replies

November 27, 2012

So another strange issue... Setting session variables no longer works.  I found this thread which is somewhat similar http://forums.adobe.com/message/4049838 but he/she was able to set session vars at least.

12Robots
Participating Frequently
November 27, 2012

Where is the code where you are setting your cookies? You need to be setting them manually somewhere (Application.cfm) because you have setClientCookies="no".

jason

November 27, 2012

It's in the Application.cfm.  Here is an example...

<cfcookie domain=".kyndoutdoors.com" name="kp_username" value="#get_user_via_cookies.username#" expires="never"/>
November 27, 2012

Another thing I'm noticing as I'm trying to figure this out is that the cookies I'm setting and the cfid/cftoken variables are getting duplicated.  Seems strange....