文章作者 : Nathan Stanford [ fengjf@novasprint.com ] Web URL : http://
上载日期 : 2000-11-23
注意:这是由国外的网页转来的资料.
问题:
How do you kill session variables effectively when the user has
their browser set to never check for new pages? We are
currently using a combination of the following:
1. <CFHEADER NAME="Expires" VALUE="#Now()#">
2. <CFCOOKIE NAME="CFID" VALUE="#Session.CFID#">
<CFCOOKIE NAME="CFTOKEN" VALUE="#Session.CFTOKEN#">
3. <cfset structdelete(SESSION, "LOGIN")>
(We do this for each of the session variables. We tried
cfstructclear(session) to clear all the session variables at
once, but it did not seem to be working.)
回答:
First we need to understand WHY are we using Session Variables
when people login we tend to keep track of if they are logged
in or not in a session or client variable. So there is more
then one way to do this.
1. Session Variables:
Session Variables are a great thing to use when making a
detailed application on the web but if you want to do
load balancing I would recommend you move to Client
Variables. Read the Client Variables section
This should Clear everything in the structure.
<CFScript>
StructClear(session);
</CFScript>
and
You set a cookie when the user logs in and don't put a
expiration date which will make it expire when the browser
is closed.
Now if you check for the session variable that you picked to
tell you that the user is logged in and you check the cookie
you will get a true picture as to who is logged in.
2. Client Variables:
Why use Client variables?
If you plain to do load balancing across servers then you
should use client variables so that the client variables can
be stored in the database and this will then allow for load
balancing across multiple servers.
Setup Client Variables?
If you use client variables you should go into the ColdFusion
administration page and setup a database to be able to use
Client Variables.
Below is calling a stored procedure that deletes all of the
information in the database you
<cfquery name="qry_ClearClientVars" datasource="MyDSN">
sp_logoutuser
@cfid ="#cfid#:#cftoken#"
</cfquery>
|