Skip to main content
Inspiring
November 23, 2011
Frage

cfcookie not working (CF9)

  • November 23, 2011
  • 2 Antworten
  • 7919 Ansichten

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.

Dieses Thema wurde für Antworten geschlossen.

2 Antworten

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#">

plartsAutor
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.

plartsAutor
Inspiring
November 28, 2011

Ah, IFrames. This immediately got me thinking about the third-party-cookie problem. What happens when you add the following header to Application.cfm (or alternatively to the onRequeststart method of Application.cfc)?

<cfheader name="P3P" value="CP='IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT'">


I add this line in "application.cfm"

same behaviour.

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?

plartsAutor
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

There are typically 2 common reasons why cookies do not get set in CF applications:

  1. The developer is trying to set a cookie and then performs a cflocation redirect.  In this case, the redirect command is sent to the browser and the browser never receives the cookie set command
  2. The user's browser rejects the cookie due to security/privacy issues.  Typically you will see this if the site is missing a P3P privacy policy - many modern browsers reject cookies outright from sites that don't declare their intentions on how they want to use the data.