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!

Cookies not being set

Status
Not open for further replies.

calista

Programmer
Jan 24, 2001
545
US
I have been using session variables to log people into my intranet site, but some users find it a nuisance to log in every time, and have suggested I set cookies. Hey, I'm flexible. When I try to set a cookie during the login process, they don't get created. What am I missing?

Here is my CFAPPLICATION:
Code:
<CFAPPLICATION NAME=&quot;TLGD_Intranet&quot;
               CLIENTMANAGEMENT=&quot;Yes&quot;
               SESSIONMANAGEMENT=&quot;Yes&quot;>
I previously had SETCLIENTCOOKIES=&quot;YES&quot;, and it didn't work.

Now, for a clip from my login routine:
Code:
<!--- If the user exists, set the flags --->
	<CFLOCK TIMEOUT=&quot;10&quot; THROWONTIMEOUT=&quot;Yes&quot; TYPE=&quot;EXCLUSIVE&quot; SCOPE=&quot;SESSION&quot;>
		<CFIF QGETUSER.RECORDCOUNT EQ 1>
			<CFSET SESSION.LOGIN = &quot;true&quot;>
			<CFSET SESSION.USER.ID = &quot;#QGETUSER.PERSONID#&quot;>
			<CFSET SESSION.USER.NAME = QGETUSER.PERSONFIRSTNAME&QGETUSER.PERSONLASTNAME>
			<CFCOOKIE NAME=&quot;User.ID&quot; VALUE=&quot;#QGETUSER.PERSONID#&quot; EXPIRES=&quot;30&quot;>
			<CFSET CALLER.CF_AUTHENTICATE = &quot;success&quot;>
		
		<!--- If there are too many or too few records, flag an error --->
		<CFELSE>
			<CFSET CALLER.CF_AUTHENTICATE = &quot;failure&quot;>
    	</CFIF>
	</CFLOCK>
When I try to reference #Cookie.User.ID# later, it doesn't exist. It's something simple, I'm sure. Calista :-X
Jedi Knight,
Champion of the Force
 
Are you using CFLOCATION in the page? If so you cannot use CFLOCATION on a page that sets cookies.

A cookie is client side, whereas CFLOCATION is server side. A cookie is set when a page is fully loaded. If you use CFLOCATION it will redirect the page before the page fully loads. This is to your advantage if you don't want the entire page loaded. However, a cookie cannot be set using this. The alternative is to either use...

1. JavaScript:
a. location.href = &quot;mypage.cfm&quot;
b. location.replace(&quot;mypage.cfm&quot;) <-- I prefer this one

OR

2. Metatag
a. <meta http-equiv=&quot;Refresh&quot; content=&quot;0 URL=&quot;mypage.cfm&quot;>

See:


Of course, if you don't have CFLOCATION in the page or an included page, it may be something else.
- tleish
 
Thanks, tleish! You reminded me of something I'd forgotten about cookies. At the top of my protected pages, I CFINCLUDE some code that checks for the existance of SESSION.USER.ID, and if it doesn't find it, presents the login screen. When the user logins in, he is taken to whatever page he was originally trying to get to. However, I see this won't work with cookies.

CFHub, I'll take a look at that link you included. Thank you! Calista :-X
Jedi Knight,
Champion of the Force
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top