Ok, last night in the wee hours trying to fend off sleep, I tried adding
cookies to my site.  I've been using Session variables for a while but have
noticed that my provider, Interland, seems to reset the CF server I'm on
fairly often.  I don't know if there's a memory leak or someone's running
bad code or what, but before just trying to get them to move my site to a
different box, I thought I would at leas try the cookie thing.  Not having
done this before, I checked in both Forta books and the Danesh book but they
were only minimally helpful.  All I wanted to do was to set a cookie when
someone logged in that has their userid, and then remove it when/if they log
off.  I also wanted to keep the session varables so wanted to do checks for
the cookie if the user was not logged in with session variables and if the
cookie was found but the user wasn't logged in with session vars, that
should mean that the CF Server was reset in that timeframe, so I wanted to
log them back in.

So, I though, that shouldn't be that hard, I'll just play around.  Well, a
few hours later, I think I have it working, but I just want to confirm the
assumptions I came to after wracking my brain for that time.  First of all,
it seems that the cfcookie tag only works in application.cfm.  Is this
right?  If so there was no mention of this in any of the books that I could
see.  Second, the Danesh book was helpful enough to say that to delete a
cookie you set expire=NOW.  But as I found out, the cookie still remains on
your computer and so of course when you check for the cookie as I was
initially doing by doing a IsDefined(cookie.cookiename), it would still find
the cookie.  So, in addition to expiring the cookie now, I had to also set
the value to "" and then when I check for the cookie, in addition to
checking whether it's defined, I check for it being blank.  Is this just
totally messed up?  I've done some testing and it seems to work the way I
intend, but I'm wondering whether this is total inefficient, or if I've come
to all the wrong assumptions about cookies?

I'll just give you the critical code for the pages mentioned above

Here's the code that does the logging in:

<!--- First Check  to make sure the username/password is correct --->
<cfif getUsers.recordcount neq 0>
        <!--- If it is then set the session variables --->
        <cfset session.userAuth="1">
        <cfset session.userid="#getusers.keyUserID#">
        <cfset session.username="">
        <cflocation url="indexnew.cfm?varArea=reviews">
<cfelse>
        <!--- If username/password isn't correct, forward user to error page --->
        <cflocation url="indexnew.cfm?varArea=register&wrong=yes">
</cfif>

Here is my signout page:

<cfset session.username="">
<cfset session.email="">
<cfset session.realname="">
<cfset session.userAuth="">
<cfset session.userid="">
<cfset session.username="">
<cfset session.location="">
<cfset session.password="">
<cfset session.url="">
<cfset session.blurb="">
<cfset session.reviewer="">
<cfset session.show="">
<cfset session.signout="1">
<cflocation url="indexnew.cfm">


Here is my application.cfm file:

<!--- Set up the application.cfm for enabling session variables --->
<cfapplication name="userauthenticate"
         sessionmanagement="Yes"
         SESSIONTIMEOUT=#CreateTimeSpan(365,1,1,1)#
    APPLICATIONTIMEOUT=#CreateTimeSpan(365,1,1,1)#>

<!--- Create a default blank userID for error trapping --->
 <cfparam name="Session.signout" default="">
 <cfparam name="Session.userAuth" default="">
 <cfparam name="Session.userid" default="">
 <cfparam name="Session.reviewer" default="0">
 <cfparam name="vararea" default="">

<cfif session.signout eq 1>
        <!--- If the user just signed off, expire their cookie and reset the
signout session variable  --->
        <cfcookie name="dvdmon" value="" expires="NOW">
        <cfset session.username="">
        <cfset session.email="">
        <cfset session.realname="">
        <cfset session.userAuth="">
        <cfset session.userid="">
        <cfset session.username="">
        <cfset session.location="">
        <cfset session.password="">
        <cfset session.url="">
        <cfset session.blurb="">
        <cfset session.reviewer="">
        <cfset session.show="">
        <cfset session.signout="">
</cfif>

<!--- Cookie Management --->


<!--- Check to see Whether the user just signed off --->


<!--- Check to see if there is a cookie on the user's machine --->
<cfif NOT isDefined("cookie.dvdmon")>
        <!--- If No cookie there, check to see whether they are logged in via
session variables --->
        <cfif session.userid neq "">
                <!--- If they are logged in, write a cookie to their machine --->
                <cfcookie name="dvdmon" value="#session.userid#" expires="NEVER">
        </cfif>
<cfelse>
        <!--- If cookie IS there, check to see whether they are logged in via
session variables --->
        <!--- Even if it is, check to make sure it's not expired --->
        <cfif cookie.dvdmon neq "">
                <cfif session.userid eq "">
                        <!--- If they are NOT logged in, set all the session variables 
--->
                        <cfset session.userAuth="1">
                        <cfset session.userid="#cookie.dvdmon#">
                        <cfset session.username="">
                </cfif>
        </cfif>
</cfif>


Any insite would be greatly appreciated!  Thanks,

Levi

------------------------------------------------------------------------
| Levi Wallach - [EMAIL PROTECTED]  P:(703) 237-0443 F: 703-237-3490    |
| Senior Webmaster, Tran Interactive Design Group - http://www.tidg.com |
------------------------------------------------------------------------
| Creator, DVDMON.com - http://www.dvdmon.com - [EMAIL PROTECTED]         |
| DVD News, Views & Reviews, Music & Book Reviews, PDA Channel Content, |
| Contests, DVD Buying Guide and more!                                  |
-------------------------------------------------------------------------

------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to