Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem showing Logged in Users w/Application/Session?

Status
Not open for further replies.

kelani

MIS
Nov 29, 2000
44
0
0
US
Greetings,

I've been working with my variables for some time, trying to develop a nice "who's online" page. I've read tutorials, and even tried examples that will output ONE variable, but anything beyond that.. gets interesting.

When a user logs in, these variables are set..

<cfset session.loginname = #uname#> (username)
<cfset session.email = #email#> (email address)
<cfset session.uid = #id#> (their unique ID)

I am using the &quot;Trackman&quot; system from in my Application.cfm, which looks something like this... (pardon the length)


-------------application.cfm--------------
<cfapplication name=&quot;login&quot; clientmanagement=&quot;Yes&quot; sessionmanagement=&quot;Yes&quot; setclientcookies=&quot;Yes&quot; SESSIONTIMEOUT=#CreateTimeSpan(0, 0, 30, 0)# APPLICATIONTIMEOUT=#CreateTimeSpan(0, 0, 30, 0)# clientstorage=&quot;Cookie&quot;>


<!---Does the Application.Online variable exist yet?--->
<cflock name=&quot;TrackMan&quot; type=&quot;ReadOnly&quot; timeout=&quot;5&quot;>
<cfif IsDefined(&quot;Application.Online&quot;)>
<cfset CreateStructure=FALSE>
<cfelse>
<cfset CreateStructure=TRUE>
</cfif>
</cflock>

<!---Create Application.Online (once only)--->
<cfif CreateStructure>
<cflock name=&quot;TrackMan&quot; type=&quot;Exclusive&quot; timeout=&quot;5&quot;>
<cfset Application.Online=StructNew()>
</cflock>
</cfif>

<!---Remove &quot;old&quot; users (&quot;TimeOut Minutes&quot;)--->
<!---First build a list of users &quot;older&quot; than &quot;TimeOut&quot;--->
<cfset TimeOut=90>
<cfset UserList=&quot;&quot;>
<cflock name=&quot;TrackMan&quot; type=&quot;ReadOnly&quot; timeout=&quot;10&quot;>
<cfloop collection=&quot;#Application.Online#&quot; item=&quot;ThisUser&quot;>
<cfif DateDiff(&quot;n&quot;,Application.Online[ThisUser][1],now()) GTE TimeOut>
<cfset UserList=ListAppend(UserList,ThisUser)>
</cfif>
</cfloop>
</cflock>

<!---Then delete &quot;old&quot; users--->
<cfloop list=&quot;#UserList#&quot; index=&quot;ThisUser&quot;>
<cflock name=&quot;TrackMan&quot; type=&quot;Exclusive&quot; timeout=&quot;5&quot;>
<cfset Temp=StructDelete(Application.Online,ThisUser)>
</cflock>
</cfloop>


<!---Build &quot;This&quot; Members &quot;Info&quot; Array--->
<cfscript>
Members=ArrayNew(1);
Members[1]=now();
Members[2]=CGI.CF_Template_Path;

</cfscript>

<cfif IsDefined('Session.loginname')>
<cflock name=&quot;TrackMan&quot; type=&quot;Exclusive&quot; timeout=&quot;5&quot;>
<cfset Temp=StructInsert(Application.Online,Session.loginname,Members,TRUE)>
</cflock>

<cfelse>
</cfif>

--------end of application.cfm--------------------

The &quot;results&quot; page lookslike this, and pullsinformation from the temp structure. It's hard to follow.

My main problem has been a) &quot;error resolving parameter&quot; for the email, username, etc..


--------------results (who's on) page---------------

<CFSET SESSION.LOGGEDIN = FALSE>

<cflock timeout=&quot;5&quot; throwontimeout=&quot;No&quot; type=&quot;READONLY&quot; scope=&quot;APPLICATION&quot;>
<cfquery name=&quot;CheckUser&quot; datasource=&quot;db26401a&quot; username=&quot;us26401a&quot; password=&quot;dxm714&quot; dbserver=&quot;localhost&quot; dbname=&quot;db26401a&quot;>
SELECT Uname, id, email, photo
FROM users
WHERE uname = '#Form.uname#'
</cfquery>
</cflock>

<!-- Is the user present in the database? -->
<CFIF CHECKUSER.RECORDCOUNT GREATER THAN 0>

<!--- Passwords are not case-sensitive in this application (use Compare() if you want to enable case sensitivity) --->

<!-- Does the application structure exist? If not, create one -->
<CFIF #ISDEFINED(&quot;application.UsersLoggedin&quot;)# IS FALSE>
<CFSET APPLICATION.USERSLOGGEDIN=STRUCTNEW()>
</CFIF>

<CFSET USERIDATDOOR = CHECKUSER.uname>
<!-- Is there a user already using this login? -->
<CFIF #STRUCTKEYEXISTS(APPLICATION.USERSLOGGEDIN, USERIDATDOOR)# IS TRUE>
<!-- If so, we check if the session is 'virtually' timed out -->
<CFSET ENDTIME = #APPLICATION.USERSLOGGEDIN[USERIDATDOOR].TIMECREATED# + #APPLICATION.TIMEOUT#>
<CFIF #DATECOMPARE(&quot;#Now()#&quot;, &quot;#EndTime#&quot;)# IS 1>
<!-- If the application variable is timed out then we delete the user from the structure, to leave some room for the new user -->
<CFOUTPUT>
<CFSCRIPT>
StructDelete(application.UsersLoggedin, #CheckUser.uname#, true);
</CFSCRIPT>
</CFOUTPUT>

<!-- These Session variables are used to control the login validity through the application using the application.cfm -->
<CFSET SESSION.LOGGEDIN = TRUE>
<CFSET SESSION.uname = CHECKUSER.uname>

<!-- We then add the current user session structure to the Application structure -->
<CFSET APPLICATION.USERSLOGGEDIN[&quot;#session.uname#&quot;] = SESSION>
<!-- We add a time stamp to determinate the approximate timeout in case of an unexpected departure of the user -->
<CFSET APPLICATION.USERSLOGGEDIN[&quot;#Session.uname#&quot;].TIMECREATED = NOW()>

<CFELSE>
<!-- If the session of the user currently logged in is not over, we display a message -->
<CFOUTPUT>
<CFIF #DATEDIFF(&quot;n&quot;, &quot;#Now()#&quot;, &quot;#EndTime#&quot;)# LT 1>
<CFSET MINUTESLEFT = 'LESS THAN ONE'>
<CFELSE>
<CFSET MINUTESLEFT = #DATEDIFF(&quot;n&quot;, &quot;#Now()#&quot;, &quot;#EndTime#&quot;)#>
</CFIF>
<CFSET REASON = &quot;: \n\n1- User #CheckUser.UserID# is already logged-in.\n2- OR you have terminated your last session abnormaly (e.g. your computer crashed).\n\nThis account will be unlocked in: #MinutesLeft# minute(s) from now.\n\nTo obtain more licenses, please contact our sales team.&quot;>
</CFOUTPUT>
</CFIF>

<!-- if we don't detect any user already logged in with the same login, we give the user access to the application -->
<CFELSE>
<!-- These Session variables are used to control the login validity through the application using the application.cfm -->
<CFSET SESSION.LOGGEDIN = TRUE>
<CFSET SESSION.uname = CHECKUSER.uname>

<!-- We then add the current user session structure to the Application structure -->
<CFSET APPLICATION.USERSLOGGEDIN[&quot;#session.uname#&quot;] = SESSION>
<!-- We add a time stamp to determinate the approximate timeout in case of an unexpected departure of the user -->
<CFSET APPLICATION.USERSLOGGEDIN[&quot;#Session.uname#&quot;].TIMECREATED = NOW()>

</CFIF>

<!-- if the password was incorrect -->

<!-- if the username was not present in the database -->
<CFELSE>
<CFOUTPUT>
<CFSET REASON = 'I COULD NOT FIND A USER NAMED #FORM.uname# HERE.'>
</CFOUTPUT>
</CFIF>

<!-- If the user is authenticated we transfer him/her to the homepage -->
<CFIF SESSION.LOGGEDIN>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
self.location ='page1.cfm';
</SCRIPT>

<!-- If not we transfer the user to the login page -->
<CFELSE>
<CFOUTPUT>
<SCRIPT>
alert(&quot;Sorry! Your login was unsuccessful because #Reason#&quot;);
self.location=&quot;login.cfm&quot;;
</SCRIPT>
</CFOUTPUT>

</CFIF>

---end of results---------------


End of novel, any ideas, or simpler templates? :)





The Land of Broken Dreams 9 -
9.1 million visitors since 1992
Register today, and get sexy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top