Session 注销并终止会话
我有一个登录页面,工作正常。现在我想注销Session 注销并终止会话,session,coldfusion,coldfusion-9,logout,coldfusion-10,Session,Coldfusion,Coldfusion 9,Logout,Coldfusion 10,我有一个登录页面,工作正常。现在我想注销 <a id="login-link" href="login.cfm"> <cfif session.userLoggedIn>logout <cfelse>LogIn</cfif> </a> 下面是my header.cfm文件中的链接。如果会话变量为true则会显示“注销”。如果没有,则显示“登录”。所以我只想注销 <a id="login-link" href="logi
<a id="login-link" href="login.cfm">
<cfif session.userLoggedIn>logout <cfelse>LogIn</cfif>
</a>
下面是my header.cfm文件中的链接。如果会话变量为true
则会显示“注销”。如果没有,则显示“登录”。所以我只想注销
<a id="login-link" href="login.cfm">
<cfif session.userLoggedIn>logout <cfelse>LogIn</cfif>
</a>
logIn.cfm
<cfif isDefined("form.btn_login") >
<cfset userResultResponse = communtiyServic.getUsers(form.user,form.pwd)>
<cfset userQry = userResultResponse.getQryData() >
<cfif userQRY.recordCount gt 0 >
<cfset session.userLoggedIn = true />
<cflocation url="index.cfm" >
<cfelse>
<cfoutput>invaled userName or password </cfoutput>
</cfif>
</cfif>
无效的用户名或密码
如果您正在使用CFID
和CFTOKEN
作为会话标识cookie(您可能不应该这样做,但这是默认设置),那么您只需调用注销()方法即可。这将使服务器和客户端之间的会话连接无效。我不确定它是否会使服务器上的会话数据过期,但如果不是,它将在超时后自动超时。同时,它在客户端将无法访问,无论出于何种目的,客户端都能满足您的需要。编辑500编辑后修复措辞这里是一个带有示例代码的答案……我做了一些更改,以简化过程,并使用url查询字符串从任何页面注销。还有其他方法,但这可以用于OPs示例
在onRequestStart()中,添加一些代码以查找注销/重定向,从而将location()用于登录页面
OP使用现有代码实现注销/重定向的一种简单方法是在onRequestStart()中添加如下内容:
难道你不需要一个将session.userLoggedIn设置为false的注销页面来注销用户吗?Sessioninvalidate…这是多玩家功能。很好,啊!我有自动完成的忍者d。我是说多用途@弗兰克都铎,你为什么不干脆编辑你的评论?@DanBracuk:他可能以为我已经读过了,所以事后编辑不会有任何帮助,但新的评论会引起新的通知。@DanBracuk我在起床洗澡和开始新的一天之前在android手机上回答了问题。我在上班的路上注意到了这一点……在我的代表级别,我没有评论编辑功能(大约一分钟后)…(向天空举起拳头……“诅咒你的安卓神灵和你的自动更正技巧!”):你能举一个更有趣的例子吗?@JamesAMohler我更新了我的答案,并准备了一个例子
param name="url.logout" default=0;
if (isDefined('url.logout') and url.logout) {
if (isDefined('session')){
/*
You can use structDelete(session,'whatever')
if you know the session.whatever you are clipping
and you will have to loop and kill all SO
try the structClear() function below.
*/
structClear(session);
/*
The OP can redirect to login.cfm
which will auto take them to the login.cfm page
provided you tack on the ?logout=1 to the URL like this
http://yoursite.com/somepage.cfm?logout=1
*/
location(url="login.cfm");
}
}