Solved

User Queue / Verifying Session Status

Posted on 2004-08-11
5
242 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 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Very nice!  Thank you.
0
 
LVL 25

Expert Comment

by:James Rodgers
Comment Utility
glad I could help

thanks for the points
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

16 Experts available now in Live!

Get 1:1 Help Now