Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

User Queue / Verifying Session Status

Posted on 2004-08-11
5
Medium Priority
?
267 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview

885 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