Skip to main content
Inspiring
November 23, 2011
Question

cfcookie not working (CF9)

  • November 23, 2011
  • 2 replies
  • 7919 views

I use this line of CF code to set new cookies :

<cfcookie name="PLARTS_MAIL_USERNAME" value="#trim(form.username)#" expires="410">

And i cannot see my cookie in FireFox , or readding it with Javascript,

or using CF read with : <cfparam name="cookie.PLARTS_MAIL_USERNAME" type="string" default="" />

It always return "blanc" , not existing.

(I can see other cookies from other Sites).

Any idea ? any help thanks.

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
November 24, 2011

plarts wrote:

I use this line of CF code to set new cookies :

<cfcookie name="PLARTS_MAIL_USERNAME" value="#trim(form.username)#" expires="410">

And i cannot see my cookie in FireFox , or readding it with Javascript,

or using CF read with : <cfparam name="cookie.PLARTS_MAIL_USERNAME" type="string" default="" />

It always return "blanc" , not existing.

(I can see other cookies from other Sites).

Two points:

1) If your application file is Application.cfm, then give the attribute setClientCookies (in the cfapplication tag) the value "yes". If you're using Application.cfc instead, then give this.setClientCookies the value "yes".

2) I created the following 2 CFM pages, and ran testPage.cfm. It works!

cookiePage.cfm

<cfcookie name="bkbk" value="testing testing 1, 2, 3" expires="10">

testPage.cfm

<cfinclude template="cookiePage.cfm">

<cfdump var="#cookie#">

plartsAuthor
Inspiring
November 24, 2011

I fully agree with what you did.

outside my application, all is working well. (small testing)

Inside my application, not.

But it is simple, there is a form for LOGIN.

When submitted, I create the cookies, works well, I can see my cookies.

If I refresh the page, (so resubmit, which is the same process) the cookies are lost.

I mean, I cannot see them anymore.

If I go to another page after the Login, same, the cookies are lost.

And there is nowhere expires='now' for these cookies.

OK, I give up. I keep it like this, no cookies for the LOGIN. (I only use the session variable to remember)

In same application, I use another cookie elsewhere, all is working fine.

BKBK
Community Expert
Community Expert
November 25, 2011

plarts wrote:

...

outside my application, all is working well. (small testing)

Inside my application, not.

...

In same application, I use another cookie elsewhere, all is working fine.

It is confusing what you describe as "inside" and "outside" of your application. Could you please explain how you tell the difference. It might be that one part of your code is setting the cookie, whereas another is deleting it.

Inspiring
November 23, 2011

What happens if you dump out your COOKIE scope immediately after setting it?

<cfcookie name="PLARTS_MAIL_USERNAME" value="#trim(form.username)#" expires="410">
<cfdump var="#COOKIE#">

Also, you're not doing a <cflocation> on the same page that you are setting your cookie are you?

plartsAuthor
Inspiring
November 23, 2011

Thanks for this view with Dump.

I did a small program to set cookies and read them, it does work.

But inside my application , it does not work, no cookies are created.

So I think I have to look deeply in the apllication, why it does does not work.

Inspiring
November 23, 2011

My understanding is now :

If the cookies are set with a CFINCLUDE of the file doing the cookies,

it does not work.

If the cookies are set inside the primary file, it does work.

Can you understand this ?


I think we'd have to see some sample code in order to offer any additional suggestions at this point.