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
865 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
9 Comments
 
LVL 21

Accepted Solution

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

Expert Comment

by:pinaldave
ID: 12277885
0
 
LVL 1

Author Comment

by:JUSTICE
ID: 12277932
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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 9

Assisted Solution

by:CFDevHead
CFDevHead earned 250 total points
ID: 12278241
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
 
LVL 1

Author Comment

by:JUSTICE
ID: 12278554
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
ID: 12278905
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
ID: 12278923
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
ID: 12279023
Glad we could help
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 12279173
wonderful!
0

Featured Post

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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