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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enabling cookies in CF 3

Status
Not open for further replies.

hpvic03

Technical User
Aug 2, 2006
89
0
0
i am trying to use cookies to remember a user after they log in, but my colffusion server won't send me my own cookies. I made a test code to make sure. this is it:

1st page:

<cfcookie name="test" value="Accepts_cookies">
<cflocation url="test2.cfm">

2nd page (named test2.cfm):


<cfif IsDefined(Cookie.test)> <cfif Cookie.test eq "Accepts_cookies">
<cfoutput> User Accepts Cookies</cfoutput>
<cfelse>
<cfoutput> User Doesn't Accept Cookies</cfoutput>
</cfif>
<cfelse>
<cfoutput>User Doesn't Accept Cookies</cfoutput>
</cfif>

And it tells me my browser doesn't accept cookies, and i can't find the cookie in the cookie folder. What is wrong?
 
sorry, forgot to mention that they are enabled already. thats whats confusing me
 
Is your cfapplication variable setClientCookies set to No? Check in your relevant Application.cfm file

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
well at first i had no application file, but now i made one and made setClientCookies = "yes", and it still doesn't work. any ideas?
 
Code:
<cfcookie name="test" value="Accepts_cookies">
<cflocation url="test2.cfm">

you cannot set a cookie on the same page as a server side re-direct. You should use javascript to do the move to test2.cfm, not cflocation.

=========================================
Don't sweat the petty things and don't pet the sweaty things.
 
ok, here's my new code using javascript:

<cfcookie name="test" value="Accepts_cookies">
<html>
<body onload="timer=setTimeout('move()',1)">
<script language="JavaScript">
var time = null
function move() {
window.location = 'test2.cfm'
}
</script>
</body>
</html>

and it still isn't giving me a cookie! I'm pretty sure the re-direct isn't the root of the problem, because i tried taking the redirect out, so it was just:

<cfcookie name="test" value="Accepts_cookies">

then, i manually typed in the address for test2.cfm and it still doesn't detect it. what is wrong??
 
and i just read that the cfcookie/cflocation issue has been resolved since cfmx, whaddyaknow.

well then i would suggest finding out if the server is not sending the cookie, or your browser is not accepting it (more likely).

i like to use the liveHttpHeaders plugin for firefox to watch the header information to see what cookies are being sent. If you see a cookie in the headers of the first page then the server is doing it's job and you know something is up with your machine.

(liveHttpHeaders)

which brings up another question, have you simply tried this from another computer to see if the cookie is picked up?

=========================================
Don't sweat the petty things and don't pet the sweaty things.
 
alright, well the header told me the cookie was being sent, so i changed the code on the second page (test2.cfm) to:
<cfoutput> #cookie.test# <cfoutput>

and it gave me the correct value, so there must be something weird with using the isDefined() function with cookie variable... i dk... thanks for all of your help!
 
now that i look at it i think the problem was this

<cfif IsDefined(Cookie.test)>

should be

<cfif IsDefined("Cookie.test")>



=========================================
Don't sweat the petty things and don't pet the sweaty things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top