I'm using a login page that works fairly efficiently AFTER users have been 'helped' by me to get logged in properly for the first time. Here is application.cfm:
<cfapplication name="HR" sessionmanagement="Yes" sessiontimeout="#CreateTimeSpan(0,0,20,0)#" applicationtimeout="#CreateTimeSpan(0,0,20,0)#">
<cferror type="REQUEST" template="error.cfm">
<cfparam name="session.SSN" default="False">
<cfparam name="session.LoggedIn" default="false">
<cfparam name="session.LoginID" default="false">
<cfset apptimespan = #createtimespan(0,0,20,0)#>
<CFIF #session.loggedin# IS "False">
<CFIF (CGI.SCRIPT_NAME IS NOT "login.cfm" AND (CGI.SCRIPT_NAME IS NOT "results.cfm>
<SCRIPT LANGUAGE="JavaScript">
alert("The system has detected an invalid login or your session on this machine has timed out. You will be prompted for your login/password again. If this error continues, try again in 20 minutes. We apologize for the inconvenience."
self.location="login.cfm";
</SCRIPT>
</CFIF>
<CFELSE>
<CFIF (CGI.SCRIPT_NAME IS NOT "login.cfm" AND (CGI.SCRIPT_NAME IS NOT "results.cfm>
<CFSET APPLICATION.USERSLOGGEDIN["#Session.LoginID#"].TIMECREATED = NOW()>
</CFIF>
</CFIF>
Users will often get "timeout" errors the first time they log in even if they use the right login name and password. I can 'fix' this error by changing the timeout from 20 to 0 minutes and then back again. I'm not understanding why this will happen. Is there something wrong with the code, or is there something I can add that will keep this from happening?
application.cfm feeds results.cfm. This page has session variables set for a pick list of all the applications that a user is set to see. All users are not allowed to see all applications, but another error that a first time logger will get is an unrecognized variable mentioning each one of the applications in turn.
The code on the actual menu page looks like this:
<cfif session.HRappName IS "1">
<tr>
<td>
<a href="HRappName.cfm">HRappName</a>
</td>
</tr>
</cfif>
Each application name has a variable set and if I only comment out the first one, each if is "1" statement will get an error in its turn.
The code on results.cfm looks like this:
<cfset session.loggedin=false>
<cfquery name="CheckUser" datasource="Master">
SELECT *
FROM Login
WHERE LoginID = '#Form.LoginID#'
</cfquery>
<cfset session.OneHRapp = "#CheckUser.OneHRapp#">
<!---And a whole bunch more applications listed--->
<cfquery name="getSSN" datasource="Master">
SELECT *
FROM Atable
WHERE SSN='#session.SSN#'
</cfquery>
<cfif CheckUser.RecordCount greater than 0>
<cfif CheckUser.PwsWd IS FORM.PwsWd>
<cfif #IsDefined("application.UsersLoggedIn"# IS False>
<cfset application.UsersLoggedIn=StructNew()>
</cfif>
<cfset UserIDatDoor=CheckUser.LoginID>
<cfif #StructKeyExists(application.UsersLoggedIn, UserIDatDoor)# IS True>
<cfset EndTime=#application.UsersLoggedIn[UserIDatDoor]. TimeCreated# + #AppTimeSpan#>
<cfif #DateCompare("#Now()#", "#EndTime#"# IS 1>
<cfoutput>
<cfscript>
StructDelete(application.UsersLoggedin, #CheckUser.LoginID#, true);
</cfscript>
</cfoutput>
<cfset session.LoggedIn=True>
<cfset session.LoginID=CheckUser.LoginID>
<cfset application.UsersLoggedIn["#session.LoginID#"]=Session>
<cfset applicaton.UsersLoggedIn["#Session.LoginID#"]. TimeCreated=Now()>
<cfelse>
<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.LoginID# 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>
<cfelse>
<cfset session.LoggedIn=True>
<cfset session.LoginID=CheckUser.LoginID>
<cfset application.UsersLoggedIn["#session.LoginID#"] =Session>
<cfset application.UsersLoggedIn["#Session.LoginID#"]. TimeCreated=Now()>
</cfif>
<cfelse>
<cfset Reason="The password you have typed is invalid. Please try again.">
</cfif>
<cfelse>
<cfoutput>
<cfset reason ='Program unable to find #FORM.LoginID#. Please try again or contact administrator.'>
</cfoutput>
</cfif>
<cfif session.LoggedIn>
<SCRIPT LANGUAGE="JavaScript">
self.location ="ActualMenuPage.cfm";
</SCRIPT>
<cfelse>
<cfoutput>
<SCRIPT>
alert("Sorry! Your login was unsuccessful because #Reason#"
self.location="login.cfm";
</SCRIPT>
</cfoutput>
</cfif>
<cfSET session.login_id = form.loginid>
<cfif (CheckUser.PwsWd) IS "#CheckUser.SSN#">
<cflocation url="pswChng.cfm?SSN=#CheckUser.SSN#" addtoken="Yes">
</cfif>
<cfif (CheckUser.PwsWd) IS NOT "#CheckUser.SSN#">
<cflocation url="ActualMenuPage.cfm" addtoken="Yes">
</cfif>
If a user calls me to say they are getting the unrecognized variable error I comment out the if statement, have them try again and they'll get in with no problem. Then I can make the code active and they won't have any more problems in future. The problem is exacerbated when someone from a different LAN attempts to login.
What am I not seeing here? Sorry this was so long and convoluted. I hope someone can shed some light on this.
<cfapplication name="HR" sessionmanagement="Yes" sessiontimeout="#CreateTimeSpan(0,0,20,0)#" applicationtimeout="#CreateTimeSpan(0,0,20,0)#">
<cferror type="REQUEST" template="error.cfm">
<cfparam name="session.SSN" default="False">
<cfparam name="session.LoggedIn" default="false">
<cfparam name="session.LoginID" default="false">
<cfset apptimespan = #createtimespan(0,0,20,0)#>
<CFIF #session.loggedin# IS "False">
<CFIF (CGI.SCRIPT_NAME IS NOT "login.cfm" AND (CGI.SCRIPT_NAME IS NOT "results.cfm>
<SCRIPT LANGUAGE="JavaScript">
alert("The system has detected an invalid login or your session on this machine has timed out. You will be prompted for your login/password again. If this error continues, try again in 20 minutes. We apologize for the inconvenience."
self.location="login.cfm";
</SCRIPT>
</CFIF>
<CFELSE>
<CFIF (CGI.SCRIPT_NAME IS NOT "login.cfm" AND (CGI.SCRIPT_NAME IS NOT "results.cfm>
<CFSET APPLICATION.USERSLOGGEDIN["#Session.LoginID#"].TIMECREATED = NOW()>
</CFIF>
</CFIF>
Users will often get "timeout" errors the first time they log in even if they use the right login name and password. I can 'fix' this error by changing the timeout from 20 to 0 minutes and then back again. I'm not understanding why this will happen. Is there something wrong with the code, or is there something I can add that will keep this from happening?
application.cfm feeds results.cfm. This page has session variables set for a pick list of all the applications that a user is set to see. All users are not allowed to see all applications, but another error that a first time logger will get is an unrecognized variable mentioning each one of the applications in turn.
The code on the actual menu page looks like this:
<cfif session.HRappName IS "1">
<tr>
<td>
<a href="HRappName.cfm">HRappName</a>
</td>
</tr>
</cfif>
Each application name has a variable set and if I only comment out the first one, each if is "1" statement will get an error in its turn.
The code on results.cfm looks like this:
<cfset session.loggedin=false>
<cfquery name="CheckUser" datasource="Master">
SELECT *
FROM Login
WHERE LoginID = '#Form.LoginID#'
</cfquery>
<cfset session.OneHRapp = "#CheckUser.OneHRapp#">
<!---And a whole bunch more applications listed--->
<cfquery name="getSSN" datasource="Master">
SELECT *
FROM Atable
WHERE SSN='#session.SSN#'
</cfquery>
<cfif CheckUser.RecordCount greater than 0>
<cfif CheckUser.PwsWd IS FORM.PwsWd>
<cfif #IsDefined("application.UsersLoggedIn"# IS False>
<cfset application.UsersLoggedIn=StructNew()>
</cfif>
<cfset UserIDatDoor=CheckUser.LoginID>
<cfif #StructKeyExists(application.UsersLoggedIn, UserIDatDoor)# IS True>
<cfset EndTime=#application.UsersLoggedIn[UserIDatDoor]. TimeCreated# + #AppTimeSpan#>
<cfif #DateCompare("#Now()#", "#EndTime#"# IS 1>
<cfoutput>
<cfscript>
StructDelete(application.UsersLoggedin, #CheckUser.LoginID#, true);
</cfscript>
</cfoutput>
<cfset session.LoggedIn=True>
<cfset session.LoginID=CheckUser.LoginID>
<cfset application.UsersLoggedIn["#session.LoginID#"]=Session>
<cfset applicaton.UsersLoggedIn["#Session.LoginID#"]. TimeCreated=Now()>
<cfelse>
<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.LoginID# 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>
<cfelse>
<cfset session.LoggedIn=True>
<cfset session.LoginID=CheckUser.LoginID>
<cfset application.UsersLoggedIn["#session.LoginID#"] =Session>
<cfset application.UsersLoggedIn["#Session.LoginID#"]. TimeCreated=Now()>
</cfif>
<cfelse>
<cfset Reason="The password you have typed is invalid. Please try again.">
</cfif>
<cfelse>
<cfoutput>
<cfset reason ='Program unable to find #FORM.LoginID#. Please try again or contact administrator.'>
</cfoutput>
</cfif>
<cfif session.LoggedIn>
<SCRIPT LANGUAGE="JavaScript">
self.location ="ActualMenuPage.cfm";
</SCRIPT>
<cfelse>
<cfoutput>
<SCRIPT>
alert("Sorry! Your login was unsuccessful because #Reason#"
self.location="login.cfm";
</SCRIPT>
</cfoutput>
</cfif>
<cfSET session.login_id = form.loginid>
<cfif (CheckUser.PwsWd) IS "#CheckUser.SSN#">
<cflocation url="pswChng.cfm?SSN=#CheckUser.SSN#" addtoken="Yes">
</cfif>
<cfif (CheckUser.PwsWd) IS NOT "#CheckUser.SSN#">
<cflocation url="ActualMenuPage.cfm" addtoken="Yes">
</cfif>
If a user calls me to say they are getting the unrecognized variable error I comment out the if statement, have them try again and they'll get in with no problem. Then I can make the code active and they won't have any more problems in future. The problem is exacerbated when someone from a different LAN attempts to login.
What am I not seeing here? Sorry this was so long and convoluted. I hope someone can shed some light on this.