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
845 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
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
 
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

21 Experts available now in Live!

Get 1:1 Help Now