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 "Trackman" system from in my Application.cfm, which looks something like this... (pardon the length)
-------------application.cfm--------------
<cfapplication name="login" clientmanagement="Yes" sessionmanagement="Yes" setclientcookies="Yes" SESSIONTIMEOUT=#CreateTimeSpan(0, 0, 30, 0)# APPLICATIONTIMEOUT=#CreateTimeSpan(0, 0, 30, 0)# clientstorage="Cookie">
<!---Does the Application.Online variable exist yet?--->
<cflock name="TrackMan" type="ReadOnly" timeout="5">
<cfif IsDefined("Application.Online"
>
<cfset CreateStructure=FALSE>
<cfelse>
<cfset CreateStructure=TRUE>
</cfif>
</cflock>
<!---Create Application.Online (once only)--->
<cfif CreateStructure>
<cflock name="TrackMan" type="Exclusive" timeout="5">
<cfset Application.Online=StructNew()>
</cflock>
</cfif>
<!---Remove "old" users ("TimeOut Minutes"
--->
<!---First build a list of users "older" than "TimeOut"--->
<cfset TimeOut=90>
<cfset UserList="">
<cflock name="TrackMan" type="ReadOnly" timeout="10">
<cfloop collection="#Application.Online#" item="ThisUser">
<cfif DateDiff("n",Application.Online[ThisUser][1],now()) GTE TimeOut>
<cfset UserList=ListAppend(UserList,ThisUser)>
</cfif>
</cfloop>
</cflock>
<!---Then delete "old" users--->
<cfloop list="#UserList#" index="ThisUser">
<cflock name="TrackMan" type="Exclusive" timeout="5">
<cfset Temp=StructDelete(Application.Online,ThisUser)>
</cflock>
</cfloop>
<!---Build "This" Members "Info" Array--->
<cfscript>
Members=ArrayNew(1);
Members[1]=now();
Members[2]=CGI.CF_Template_Path;
</cfscript>
<cfif IsDefined('Session.loginname')>
<cflock name="TrackMan" type="Exclusive" timeout="5">
<cfset Temp=StructInsert(Application.Online,Session.loginname,Members,TRUE)>
</cflock>
<cfelse>
</cfif>
--------end of application.cfm--------------------
The "results" page lookslike this, and pullsinformation from the temp structure. It's hard to follow.
My main problem has been a) "error resolving parameter" for the email, username, etc..
--------------results (who's on) page---------------
<CFSET SESSION.LOGGEDIN = FALSE>
<cflock timeout="5" throwontimeout="No" type="READONLY" scope="APPLICATION">
<cfquery name="CheckUser" datasource="db26401a" username="us26401a" password="dxm714" dbserver="localhost" dbname="db26401a">
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("application.UsersLoggedin"
# 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("#Now()#", "#EndTime#"
# 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["#session.uname#"] = SESSION>
<!-- We add a time stamp to determinate the approximate timeout in case of an unexpected departure of the user -->
<CFSET APPLICATION.USERSLOGGEDIN["#Session.uname#"].TIMECREATED = NOW()>
<CFELSE>
<!-- If the session of the user currently logged in is not over, we display a message -->
<CFOUTPUT>
<CFIF #DATEDIFF("n", "#Now()#", "#EndTime#"
# LT 1>
<CFSET MINUTESLEFT = 'LESS THAN ONE'>
<CFELSE>
<CFSET MINUTESLEFT = #DATEDIFF("n", "#Now()#", "#EndTime#"
#>
</CFIF>
<CFSET REASON = ": \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.">
</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["#session.uname#"] = SESSION>
<!-- We add a time stamp to determinate the approximate timeout in case of an unexpected departure of the user -->
<CFSET APPLICATION.USERSLOGGEDIN["#Session.uname#"].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="JavaScript">
self.location ='page1.cfm';
</SCRIPT>
<!-- If not we transfer the user to the login page -->
<CFELSE>
<CFOUTPUT>
<SCRIPT>
alert("Sorry! Your login was unsuccessful because #Reason#"
;
self.location="login.cfm";
</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.
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 "Trackman" system from in my Application.cfm, which looks something like this... (pardon the length)
-------------application.cfm--------------
<cfapplication name="login" clientmanagement="Yes" sessionmanagement="Yes" setclientcookies="Yes" SESSIONTIMEOUT=#CreateTimeSpan(0, 0, 30, 0)# APPLICATIONTIMEOUT=#CreateTimeSpan(0, 0, 30, 0)# clientstorage="Cookie">
<!---Does the Application.Online variable exist yet?--->
<cflock name="TrackMan" type="ReadOnly" timeout="5">
<cfif IsDefined("Application.Online"
<cfset CreateStructure=FALSE>
<cfelse>
<cfset CreateStructure=TRUE>
</cfif>
</cflock>
<!---Create Application.Online (once only)--->
<cfif CreateStructure>
<cflock name="TrackMan" type="Exclusive" timeout="5">
<cfset Application.Online=StructNew()>
</cflock>
</cfif>
<!---Remove "old" users ("TimeOut Minutes"
<!---First build a list of users "older" than "TimeOut"--->
<cfset TimeOut=90>
<cfset UserList="">
<cflock name="TrackMan" type="ReadOnly" timeout="10">
<cfloop collection="#Application.Online#" item="ThisUser">
<cfif DateDiff("n",Application.Online[ThisUser][1],now()) GTE TimeOut>
<cfset UserList=ListAppend(UserList,ThisUser)>
</cfif>
</cfloop>
</cflock>
<!---Then delete "old" users--->
<cfloop list="#UserList#" index="ThisUser">
<cflock name="TrackMan" type="Exclusive" timeout="5">
<cfset Temp=StructDelete(Application.Online,ThisUser)>
</cflock>
</cfloop>
<!---Build "This" Members "Info" Array--->
<cfscript>
Members=ArrayNew(1);
Members[1]=now();
Members[2]=CGI.CF_Template_Path;
</cfscript>
<cfif IsDefined('Session.loginname')>
<cflock name="TrackMan" type="Exclusive" timeout="5">
<cfset Temp=StructInsert(Application.Online,Session.loginname,Members,TRUE)>
</cflock>
<cfelse>
</cfif>
--------end of application.cfm--------------------
The "results" page lookslike this, and pullsinformation from the temp structure. It's hard to follow.
My main problem has been a) "error resolving parameter" for the email, username, etc..
--------------results (who's on) page---------------
<CFSET SESSION.LOGGEDIN = FALSE>
<cflock timeout="5" throwontimeout="No" type="READONLY" scope="APPLICATION">
<cfquery name="CheckUser" datasource="db26401a" username="us26401a" password="dxm714" dbserver="localhost" dbname="db26401a">
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("application.UsersLoggedin"
<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("#Now()#", "#EndTime#"
<!-- 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["#session.uname#"] = SESSION>
<!-- We add a time stamp to determinate the approximate timeout in case of an unexpected departure of the user -->
<CFSET APPLICATION.USERSLOGGEDIN["#Session.uname#"].TIMECREATED = NOW()>
<CFELSE>
<!-- If the session of the user currently logged in is not over, we display a message -->
<CFOUTPUT>
<CFIF #DATEDIFF("n", "#Now()#", "#EndTime#"
<CFSET MINUTESLEFT = 'LESS THAN ONE'>
<CFELSE>
<CFSET MINUTESLEFT = #DATEDIFF("n", "#Now()#", "#EndTime#"
</CFIF>
<CFSET REASON = ": \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.">
</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["#session.uname#"] = SESSION>
<!-- We add a time stamp to determinate the approximate timeout in case of an unexpected departure of the user -->
<CFSET APPLICATION.USERSLOGGEDIN["#Session.uname#"].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="JavaScript">
self.location ='page1.cfm';
</SCRIPT>
<!-- If not we transfer the user to the login page -->
<CFELSE>
<CFOUTPUT>
<SCRIPT>
alert("Sorry! Your login was unsuccessful because #Reason#"
self.location="login.cfm";
</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.