Solved

I would like to delete an entire session.  Cflogout simply ends the session, but the variables remain on the server.

Posted on 2004-10-11
9
838 Views
Last Modified: 2013-12-24
Here is my code I am using to view active sessions (basically shows a table of all users currently logged in)

<!--- Dump all session scopes --->
      <table width="95%" align="center" cellspacing="0" cellpadding="0" bgcolor="#EBE9E9">
            <TR bgcolor="#999999">
                  <TD align="left" valign="top"><img src="../images/topleft.gif"></TD>
                  <TD colspan="5" align="center"><B>Currently Logged In Users</B>&nbsp;<I>(Click to log user out)</I></TD>
                  <td align="right" valign="top"><img src="../images/topright.gif"></td>
            </TR>
            <TR>
                  <TD>&nbsp;</TD>
                  <TD><B>Cust Code</B></TD>
                  <TD><B>User Name</B></TD>
                  <TD><B>Real Name</B></TD>
                  <TD><B>Login Date</B></TD>
                  <TD><B>IP</B></TD>
                  <TD>&nbsp;</TD>
            </TR>
      
      <cfscript>
      session.test = true;
      tracker = createObject("java", "coldfusion.runtime.SessionTracker");
      mySession = tracker.getSessionCollection( application.applicationName );
      
      for (keyname in mySession) {
         WriteOutput("<TR onclick=""parent.Action.location.href = 'action.cfm?ToDo=KillSession&Session=" & keyname & "';"" onMouseover=""this.style.backgroundColor='##FF9999';"" onMouseout=""this.style.backgroundColor='##EBE9E9';"" style=""cursor:pointer; background-color : ##EBE9E9;""><TD>&nbsp;</TD><TD>" & mySession[keyname].custcode & "</TD><TD>" & mySession[keyname].username & "</TD><TD>" & mySession[keyname].name & "</TD><TD>" & DateFormat(mySession[keyname].lastlogin, "MM/DD/YYYY") & "&nbsp;" & TimeFormat(mySession[keyname].lastlogin, "HH:MM") & "</TD><TD>" & mySession[keyname].ip & "</TD><TD>&nbsp;</TD></TR>");
      }
      </cfscript>
      </table>


On my page action.cfm, for the ToDo='KillSession', I want to be able to delete the entire structure for the given users session.

My application name is 'Secure', and the key looks like this:   secure_84301870811097497028343


My current code looks like this:  But it appears to do nothing at all, not even error out:

                <cfcase value="KillSession">
                  Deleting session <cfoutput>#URL.Session#</cfoutput><BR><cfflush>
                  
                  <cfset a = StructDelete(session, URL.Session)>
                  Done.<cfflush>
            </cfcase>

Can anyone tell me what I am doing wrong???
0
Comment
Question by:JUSTICE
  • 3
  • 3
  • 3
9 Comments
 
LVL 21

Accepted Solution

by:
pinaldave earned 250 total points
Comment Utility
use
                <cfset a = StructDelete(session, URL.Session)>
instead of
use
Structclear( URL.Session)
Regards,
---Pinal
0
 
LVL 21

Expert Comment

by:pinaldave
Comment Utility
0
 
LVL 1

Author Comment

by:JUSTICE
Comment Utility
When I do a StructClear, as it says on Livedocs, it leaves a structure out there with the session key, and it has no variables.  Then, when I try to display all sessions, it errors because the Username variable no longer exists.  How do I delete the root structure / key??
0
 
LVL 9

Assisted Solution

by:CFDevHead
CFDevHead earned 250 total points
Comment Utility
Are you trying to delete the users current session?
If so I don't think you can do that.

if not and you are just trying to delete a reg. session this should be fine

secure_84301870811097497028343
<cfscript>
StructDelete(session, 'secure_84301870811097497028343');
</cfscript>
if secure_84301870811097497028343 is also a struct I have found that you need to delete the keys out secure_84301870811097497028343 before deleting secure_84301870811097497028343 out of session
<cfscript>
StructDelete(session.secure_84301870811097497028343, 'cfide');
</cfscript>
0
Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

 
LVL 1

Author Comment

by:JUSTICE
Comment Utility
Yes, basically I am trying to force a cflogout for a given user.  

Is there any way to <cflogout> for a passed user name?
0
 
LVL 9

Expert Comment

by:CFDevHead
Comment Utility
I am sorry.  But did you say yes to this question "Are you trying to delete the users current session?"
if so I should explained a little more

Are you trying to delete the users current session that COldFusion assigns to the user?
If so you can not do this while they are still on a cfm page on your site.
0
 
LVL 1

Author Comment

by:JUSTICE
Comment Utility
OK, I think I am just going to add a bit to my application page that will check a SQL flag.

If set to 1, then do a <cflogout> and re-set flag to 0.

Its a bit more of a pain, but it should work. :)

Thanks all!
0
 
LVL 9

Expert Comment

by:CFDevHead
Comment Utility
Glad we could help
0
 
LVL 21

Expert Comment

by:pinaldave
Comment Utility
wonderful!
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now