?
Solved

User Queue / Verifying Session Status

Posted on 2004-08-11
5
Medium Priority
?
269 Views
Last Modified: 2013-12-24
My ultimate goal is to build a user queue in CF.  I want to allow a certain number of users into a restricted area at a time.  The others will be placed in a queue, informing them they are #n out of m in line, and perhaps eventually try to estimate a wait time.

I have ideas on how to do this, but I need to run a cleanup procedure that removes people who have closed their browsers from the queue.  If I store CFIDs and CFTokens into a structure, can I have a backend routine check to see if these sessions are still active, and remove them from the queue if they have expired?
0
Comment
Question by:TimDg
  • 3
  • 2
5 Comments
 
LVL 25

Accepted Solution

by:
James Rodgers earned 1000 total points
ID: 11776690
here is a code block that will determine the number of users on your site, you could use this and some other code to determine the nummber of usrs in a specific part of teh site by settign a session variable at that application and using teh code block to look for that variable, i use this in an iframe and include it on pages as needed.
yuo can also include a cfif to determine the accessibility of the application

<cfif numUsers GE x>
set queue value
redirect to waiting page
<cfelse>
set access value
redirect to app
</cfif>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
      
      <cfoutput>
            <meta http-equiv="Refresh" content="20;URL=#RELLOCPATH#users.cfm">
            <link rel="stylesheet" href="#RELLOCPATH#commonFiles/mainstyle.css" type="text/css">
      </cfoutput>
      <title>Untitled</title>
</head>

<body>

<table>
      <tr>
            <td>
                  <cfsetting enablecfoutputonly="Yes">
                        <cflock timeout="15" scope="APPLICATION" type="EXCLUSIVE">
                              <cfif NOT isDefined("Application.UsersInfo")>
                                    <cfset Application.UsersInfo = StructNew()>
                              </cfif>
                        </cflock>
                        <cflock name="#CreateUUID()#" timeout="15" type="EXCLUSIVE">
                              <cfset user_cfid = Evaluate(CFID)>
                              <cfset user_info = Now()>
                        </cflock>
                        <cflock scope="APPLICATION" type="EXCLUSIVE" timeout="15">
                              <cfif NOT StructKeyExists(Application.UsersInfo, user_cfid)>
                                    <cfset temp = StructInsert(Application.UsersInfo, user_cfid, user_info)>
                              </cfif>
                        </cflock>
                        <! --- // Ok now, we have to create a way to delete them so they don't stay in the list forever, I'm going to use a 10 minutes difference, to expire the user, remember this code should be in your application.cfm or included in your application.cfm, we are going to use the DateDiff to find out if the structure should be deleted. //--->
                        <cflock scope="APPLICATION" type="EXCLUSIVE" timeout="15">
                              <cfloop collection="#Application.UsersInfo#" item="itmUser">
                                    <cfif Evaluate(DateDiff("n", StructFind(Application.UsersInfo, itmUser), Now())) GT 10>
                                          <cfset StructDelete(Application.UsersInfo, itmUser)>
                                    </cfif>
                              </cfloop>
                        </cflock>
                        <cflock scope="APPLICATION" type="EXCLUSIVE" timeout="15">
                              <cfoutput>
                                    <cfif #StructCount(Application.UsersInfo)# EQ 1>
                                          There is #StructCount(Application.UsersInfo)# user
                                    <cfelse>
                                          There are #StructCount(Application.UsersInfo)# users
                                    </cfif>
                                    on the system.
                              </cfoutput>
                        </cflock>
                  <cfsetting enablecfoutputonly="NO">
            </td>
      </tr>
</table>
</body>
</html>
0
 
LVL 1

Author Comment

by:TimDg
ID: 11776943
Very nice solution.  Do you have a suggestion on how I can evaluate what position they hold in the queue, so I can admit them to the app when numUsers drops below the threshold?
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 11777109
you could keep an incremental copunter in a session varaible and search through the 'waiting' users to find the lowest value

session.lockedSite.isActive=1/0 1=true,0=false, if true then dont check to see if they are waiting
session.lockesite.accessNumber = 1/*  use an application variable and increment it for each user on the site, use this combined with the isActive to see if they are waiting and their position in the queue


in the iframe above you could add javascript block to advise teh user that they are being redirected to the 'locked' siet

var x=confirm("You are now entering the locked site,\nPress ok to enter or cancel to not enter\npressing cancel will lose your position in the queue")

if(x) window.location.href='lockedpage.cfm'

etc....
0
 
LVL 1

Author Comment

by:TimDg
ID: 11777121
Very nice!  Thank you.
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 11777174
glad I could help

thanks for the points
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

580 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