Solved

Session Variables again

Posted on 2006-11-15
11
154 Views
Last Modified: 2013-12-24
Experts,

I was having issues with users timing out and not being able to get back in to our app.  I put this code

<CFLOOP COLLECTION="#Session#" ITEM="sessionVar">
    <CFSET StructDelete(Session, sessionVar)>
</CFLOOP>

To help clear all session variables, and for some reason or other I am again having issues with people timing out and not getting back into the app.  Can anyone shed some light on this?  Any help would be appreciated

Thanks
nick
0
Comment
Question by:nmarano
  • 6
  • 5
11 Comments
 
LVL 24

Expert Comment

by:dgrafx
ID: 17947478
to address your loop - why don't you just use <cfset StructClear(session)> which will delete all session vars.
what is your session timeout?
0
 
LVL 2

Author Comment

by:nmarano
ID: 17947660
30 minutes.  So You're saying just place <cfset StructClear(session)>  instead of what I have?  

Thanks
Nick
0
 
LVL 24

Expert Comment

by:dgrafx
ID: 17947778
yes that will clear (delete all session.vars) users session.

how do you mean "can't get back in"?
they login and app doesnt recognize that they've logged in?
0
 
LVL 2

Author Comment

by:nmarano
ID: 17947791
Correct.  There is an error page that says session expired, which redirects them to the home page.  On the home page, when they click on the link to log in, it again redirects them to the error page saying the session expired
0
 
LVL 24

Expert Comment

by:dgrafx
ID: 17947886
ok - so on the login page - there must be some session code that is throwing the error.
post whatever session code is on login page - this include any included templates like headers, footers or whatever
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Author Comment

by:nmarano
ID: 17947934
dgrafx,

Thanks for the help

here is the code.  The log-in page is included into the teacher checklist page so I will post both pages.  Here is the login page code


<cfset CurrentPage=GetFileFromPath(GetBaseTemplatePath())>

<!--- This is the complete URL for the current page --->
<cfset ThisPageURL = "#CGI.SCRIPT_NAME#?#CGI.QUERY_STRING#">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Teacher Login Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../../Common/stylesheet.css"></link>
</head>


<body onLoad="document.TeacherLogin.lastName.focus()">
<div align="center">
<!--- Begin verification form --->
<p align="center">E-Learning for Educators Evaluation </p>
<table align="center" cellspacing="5" class="box1">
<form name="TeacherLogin" action="<cfoutput>#CurrentPage#</cfoutput>" method="POST" preservedata="yes">
<tr align="center" valign="middle">
  <th colspan="2" class="header">Teacher Login Form</th>
</tr>
<tr><td align="left" valign="bottom" colspan="2">&nbsp;</td></tr>
<tr><td align="left" valign="top">Last Name</td><td align="left" valign="top"><input type="text" name="lastName" size="28"> </td></tr>
<tr><td align="left" valign="top">Password:</td>
  <td align="left" valign="top"><input type="text" name="pw" size="28">  
    note: password is your email </td>
</tr>
<tr><td align="left" valign="top" colspan="2"><cfif IsDefined("SESSION.show_up") eq true><cfif SESSION.show_up is 1><div style="background-color:#0033CC; color:#FFFFFF; font-weight:bold; padding:4px; ">* If this is your first time visit to our website, you need to register yourself first.</div></cfif></cfif></td></tr>
<tr align="left">
<td></td>
<td>
<p>
  <input name="submit" type="submit" value="LOG IN">
  <br />
<br />
<input type="reset" value="reset">
</p>
<a href="../teacher/ws_requestPw.cfm">FORGOT PASSWORD?</a>
<input type="hidden" name="MM_InsertRecord" value="TeacherLogin">
</form>
</td></tr>
</table>
<p><a href="http://www.bc.edu/buildten"></a></p>
</div>
</body>
***********************************************************************************************
checklist.cfm code

<cfif IsDefined("SESSION.teacherID") is FALSE>
  <cflock name="Session_Lock" type="exclusive" timeout="60" throwontimeout="no">
    <cfset StructClear(session)>
  </cflock>
  <cfinclude template="ws_teacherLoginAction.cfm" >
</cfif>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>EfE Workshop Participant Checklist</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="stylesheet" type="text/css" href="../../styles/buildten.css" />
</link>
<script type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>
<style type="text/css">
<!--
.style2 {
      color: #FF0000;
      font-weight: bold;
}
-->
</style>
</head>
<body style="background-image:url(../images/efe_logo.gif); background-repeat:no-repeat; background-position: 510px 6px;">
<div id="student_home" style="width:600px; padding: 0; position:absolute; left:2em;">
  <!--- after user has been registered or logged in --->
  <cfif IsDefined("SESSION.teacherID") is TRUE>
    <cfquery name="getNames" datasource="aptvre">
    SELECT teacherFirstName, teacherLastName, pw, stateID
      FROM ws_teacher
      WHERE teacherID=#SESSION.teacherID#
    </cfquery>
       <cfset teacher_name = getNames.teacherFirstName&" "&getNames.teacherLastName>
      <!---teacher names--->
 <p><strong><cfoutput>#teacher_name#'s Checklist</strong></cfoutput></p>
    <p class="note">If you are not <cfoutput>#teacher_name#</cfoutput>, <a href="../teacher/ws_teacherLogout.cfm">click
        here</a>.</p>
            <!---find all the cohorts for this person with same last name and email --->
            <cfquery name="getCohorts" datasource="aptvre">
            SELECT *
            FROM ws_teacher      
            WHERE teacherLastName = '#getNames.teacherLastName#' AND pw = '#getNames.pw#'
            ORDER BY teacherID DESC
      </cfquery>
      <!---make a list of surveys for each cohort this person is in --->
<cfoutput query="getCohorts">

      <cfquery name="getCohortDetails" datasource="aptvre">
    SELECT * FROM ws_cohorts
    WHERE cohortID = '#getCohorts.cohortID#'
    </cfquery>
    <cfquery name="getWorkshopName" datasource="aptvre">
    SELECT workshopname, cognitive
      FROM ws_workshop
    WHERE workshopID= '#getCohortDetails.workshopID#'
    </cfquery>
       <cfquery name="getFacilitatorName" datasource="aptvre">
    SELECT lastName, firstName
      FROM ws_facilitator
    WHERE facilitatorID = '#getCohortDetails.facilitatorID#'
    </cfquery>
    <cfquery name="preSurStatus" datasource="aptvre">
    SELECT * FROM takingatest_t WHERE teacherID=#teacherID# and itemsetID = 3
    </cfquery>
    <cfquery name="postSurStatus" datasource="aptvre">
    SELECT * FROM takingatest_t WHERE teacherID=#teacherID# and itemsetID = 4
    </cfquery>
      <!---get pre survey dates--->
      <cfif getCohortDetails.start_date neq ''>
     <cfset preStart = DateAdd('d', 14, getCohortDetails.start_date)>
      <cfelse>
     <cfset preStart = ''>
      </cfif>
      <!---compare today with the start date--->
      <cfset startingStatus = #DateCompare(Now(), preStart)#>
      
      <!---DATES for ending--->
          <!---subtract a week from the end date--->
      <cfif getCohortDetails.end_date neq ''>
     <cfset postStart = DateAdd('d', -7, getCohortDetails.end_date)>
      <cfelse>
     <cfset postStart = ''>
      </cfif>
      <cfset postStart = DateAdd('d', -7, getCohortDetails.end_date)>
      <!---compare today with the end date--->
      <cfset #endingStatus# = #DateCompare(Now(), postStart)#>
      <!---compare today with the last possible date for taking the post survey--->
      <cfset postEnd = DateAdd('d', 21, getCohortDetails.end_date)>
      <cfset maxStatus = #DateCompare(Now(), postEnd)#>
<cfif maxStatus LTE 0>      
    <table border="0" width="600" cellpadding="0" cellspacing="4" style="border:solid 1px ##666666;">
    <tr>
      <td valign="bottom"><p><span style="font-weight:bold; font-size:14px;">#getWorkshopName.workshopname#:</span> <br />
         <span style="color:##666666;">Trainer: #GetFacilitatorName.firstName# #GetFacilitatorName.lastName#</span><br />
        <span style="color:##666666;">Course dates: #DateFormat(getCohortDetails.start_date, 'short')# to  #DateFormat(getCohortDetails.end_date, 'short')#</span>
        </p></td>
    </tr>
    <tr>
    <td valign="top">
    <div id="presurvey" style="background-color:##9999FF; padding: 1px 4px 1px 4px;">
      
      <p>
      <strong>Pre-Course Survey: </strong>
      <cfif  preSurStatus.yourItemsetStatus GTE 98 AND #getWorkshopName.cognitive# LT 19 AND getCohortDetails.cogOnOff EQ 0>
        <img src="../images/checkbox.gif" alt="Done" width="16" height="16" hspace="6" align="top" /> Done!
        </p>
      <cfelseif preSurStatus.yourItemsetStatus GTE 98 AND #getWorkshopName.cognitive# GT 19 AND getCohortDetails.cogOnOff GT 0>
            <!---HERE is the code for those workshops that require a PRE Cognitive Survey--->
             <p><strong>Note:</strong> this workshop has two parts.
                    Please complete both parts. Thank you!</p>
            </p><p>Part 1 of a two part survey is complete.</p>
            <cfif #getWorkshopName.cognitive# GT 1 AND getCohortDetails.cogOnOff GT 0>
             <cfquery name="preCogStatus" datasource="aptvre">
                SELECT *
                  FROM takingatest_t
                  WHERE teacherID=#teacherID# and itemsetID = #getWorkshopName.cognitive#
          </cfquery>
                   <cfif  preCogStatus.yourItemsetStatus GTE 98>
                  <p><strong>Part 2:</strong>
                  <img src="../images/checkbox.gif" alt="Done" width="16" height="16" hspace="6" align="top" /> Done!</p>
                  <cfelse>
                  <cfset cognitivePreFile = "cognitive"&#getWorkshopName.cognitive#&"_1.cfm?teacher_id=#teacherID#&itemset_id=#getWorkshopName.cognitive#">
                   <p><img src="../images/nextitemarrow.gif" alt="Next" width="16" height="16" hspace="6" /> <strong><a href="#cognitivePreFile#">Take Part 2 of the Pre-Course Survey</a></strong> </p>
                  
                   </cfif>
            </cfif>
            
            <!---END Cognitive survey section--->
        <cfelseif startingStatus LTE 0>
        </p>
            <!---Code for Worskhops requiring Cognitive Surveys--->
            <cfif #getWorkshopName.cognitive# GT 1  AND getCohortDetails.cogOnOff GT 0>
             <p><strong>Note:</strong> this workshop requires that you take a second part
               of the Evaluation surveys. <br />
               Please complete  both parts. Thank you!</p>
             </cfif>
        <!--- when there is not a record for bgsv in takingatest_f table or the status for testlet1 is 0 --->
        <cfif  preSurStatus.RecordCount is 0 or preSurStatus.yourItemsetStatus is 0>
          <cfset preSurStatus.yourItemsetStatus = 0>
        </cfif>
        <!--- after user login, dynamically link user to the next page according to their survey status --->
        <cfset yourNextPage = val( preSurStatus.yourItemsetStatus) + 1>
        <!---This is where they are going--->
        <cfset yourNextFile = "teacherPre_"&yourNextPage&".cfm?teacher_id=#teacherID#&itemset_id=3">
        <p><img src="../images/nextitemarrow.gif" alt="Next" width="16" height="16" hspace="6" /> <strong><a href="#yourNextFile#">Take  the Pre-Course Survey</a></strong></p>
            
            <cfelse>
            <p>Sorry, it is too late to take the Pre-Course Survey for this workshop.</p>
            <p><strong>IMPORTANT!</strong> If you have already registered using a different username or password PLEASE go back and log in with that information.  If you have forgotten your username or password please <a href="ws_contact.cfm">click here.</a></p>
            </cfif>
    </div>
      
<!---POST SURVEY --->

    <div id="postsurvey" style="background-color:##B7EDB8; padding: 1em 4px 1px 4px;">
    <p style="margin-top:0;"><strong>Post-Course Survey: </strong>
<cfif  startingStatus GT 0>
    <cfif #getWorkshopName.cognitive# LT 19 AND getCohortDetails.cogOnOff EQ 0 AND postSurStatus.yourItemsetStatus GTE 98>
            <img src="../images/checkbox.gif" alt="Done" width="16" height="16" hspace="6" align="top" /> Done!</p>
            <!---HERE is the code for those workshops that require a POST Cognitive Survey--->
      <cfelseif postSurStatus.yourItemsetStatus GTE 98 AND #getWorkshopName.cognitive# GT 19 AND getCohortDetails.cogOnOff GT 0>      
             <p><strong>Note:</strong> this workshop has two parts.
                    Please complete both parts. Thank you!</p>
            </p><p>Part 1 of a two part survey is complete.</p>
            <cfset postCogNum = #getWorkshopName.cognitive# + 1>
             <cfquery name="postCogStatus" datasource="aptvre">
                SELECT *
                  FROM takingatest_t
                  WHERE teacherID=#teacherID# and itemsetID = #postCogNum#
          </cfquery>
                   <cfif  postCogStatus.yourItemsetStatus GTE 98>
                   </p>
                  <p><strong>Part 2:</strong>
                  <img src="../images/checkbox.gif" alt="Done" width="16" height="16" hspace="6" align="top" /> Done!</p>
                  <cfelse>
                  <cfset cognitivePostFile = "cognitive"&#getWorkshopName.cognitive#&"_1.cfm?teacher_id=#teacherID#&itemset_id=#postCogNum#">
                   <p><img src="../images/nextitemarrow.gif" alt="Next" width="16" height="16" hspace="6" /> <strong><a href="#cognitivePostFile#">Take Part 2 of the Post-Course Survey</a></strong> </p>
                  
                   </cfif>
            
      
            <!---END POST Cognitive survey section--->
              <cfelse>
            
                  <cfif endingStatus GTE 0 AND maxStatus LTE 0>
                  </p>
                  <cfif #getWorkshopName.cognitive# GT 1  AND getCohortDetails.cogOnOff GT 0>
              <p><strong>Note:</strong> this workshop requires that you take a second part
                of the Evaluation surveys.
                Please complete
                both parts. Thank you!</p>
              </cfif>
                  <!--- after user login, dynamically link user to the next page according to their survey status --->
                  
                  <cfset yourNextPage2 = val( postSurStatus.yourItemsetStatus) + 1>
                  <cfset yourNextFile2 = "teacherPost_"&yourNextPage2&".cfm?teacher_id=#teacherID#&itemset_id=4">
                  <!---why do we need this? if they are seeing this, they already know the password! --->
                  <!---<p>FORGOTTEN YOUR ORIGINAL EMAIL/PASSWORD? <a href="ws_requestPW.cfm">Click
                here</a>.</p>--->
                  <p><img src="../images/nextitemarrow.gif" alt="Next" width="16" height="16" hspace="6" /><a href="#yourNextFile2#"><strong>Take the Post-Course Survey</strong></a></p>
                  <!---Code for Worskhops requiring Cognitive Surveys--->
            
                    <!---end of the end date check--->
                  <cfelseif endingStatus LT 0>
                  </p>
                  <p>Available after <strong>#DateFormat(postStart, 'full')#</strong> and before #DateFormat(postEnd, 'full')#.</p>
                    <cfelseif maxStatus GT 0>
                    </p>
                    <p>It is too to take the survey for this workshop. We are sorry to have missed your input.</p>
                    </cfif>
                    <!---End the postSurStatus if--->
          </cfif>
   <!---IF THE PRE-SURVEY IS NOT DONE, PRINT THIS--->
<cfelse>
    <p>Available after #DateFormat(postStart, 'full')# and before #DateFormat(postEnd, 'full')#.</p>
</cfif>
</div>

</td>
</tr>
</table>
<cfelse>
      <cfif  postSurStatus.yourItemsetStatus GTE 98>
      <p style="padding:1em; background-color:##EDE8DF; border:solid 1px ##D3CFC9; font-size:14px; ">You have completed the survey requirements for <br /><strong>#getWorkshopName.workshopname#.</strong><br />Thank you!</p>
      <cfelse>
<p style="padding:1em; background-color:##EDE8DF; border:solid 1px ##D3CFC9; font-size:14px; top:1em; position:relative;">The allotted time to complete the post-survey for <br /><strong>#getWorkshopName.workshopname#</strong><br /> has passed, please contact the <a href="ws_contact.cfm">survey coordinator</a> to be granted credit for the workshop.  </p>
      </cfif>
</cfif>
<br />
</cfoutput>
<cfelse>
<cflocation url="../error.cfm">
</cfif>
<p><span class="style2">IMPORTANT!</span> If you are taking more than one workshop, please <a href="login.cfm">register
  for the evaluation surveys</a> for <strong>EACH</strong> workshop you are taking. </p>
<p>Having problems? Check our <a href="#" onclick="MM_openBrWindow('../faq.cfm','FAQ','scrollbars=yes,resizable=yes,width=660')">Frequently
    Asked Questions</a> for solutions.</p>
<p>Please <a href="ws_teacherLogout.cfm"><strong>LOG OUT</strong></a> when
  you are finished for the day. <span style="color:#999999"> (<cfoutput>#session.teacherID#</cfoutput>)</span></p>

</div>
</body>
</html>
0
 
LVL 24

Expert Comment

by:dgrafx
ID: 17948120
1) this is how you should lock sessions
<cflock scope="SESSION" type="EXCLUSIVE" timeout="15">
<cfset session.whatever=whatever>
</cflock>
2) You need a <cfabort> where you have
<cfif IsDefined("SESSION.teacherID") is FALSE>
  <cflock scope="SESSION" type="EXCLUSIVE" timeout="15">
    <cfset StructClear(session)>
  </cflock>
  <cfinclude template="ws_teacherLoginAction.cfm" >
<cfabort>
</cfif>
unless you have that in ws_teacherLoginAction.cfm otherwise the code keeps running.
3) where is your code that takes into account for when session.teacherID is not defined?
should have something like this:
<cfif Not StructKeyExists(Session, "TeacherID")>
<cflock scope="SESSION" type="EXCLUSIVE" timeout="15">
<cfset session.TeacherID=false>
</cflock>
</cfif>
0
 
LVL 2

Author Comment

by:nmarano
ID: 17948134
#3 is in the action page.  Thanks for all the help.  I will take a look at the action page, and make the <cfabort> change
0
 
LVL 2

Author Comment

by:nmarano
ID: 17948278
I placed the <cfabort> and now the page doesn't load........hmmmmmmmm
0
 
LVL 24

Accepted Solution

by:
dgrafx earned 500 total points
ID: 17948412
instead of what you have above use this:
<cfif Not StructKeyExists(Session, "TeacherID")>
include your login form here making sure there are no references to session vars that are not defined
<CFABORT>
</cfif>

btw - what code is in ws_teacherLoginAction.cfm?
0
 
LVL 2

Author Comment

by:nmarano
ID: 17948520
Thanks, i'll give it a try

<!--- This block inside <cflogin> executes only if user is not logged in  --->
 <cflock name="Session_Lock" type="exclusive" timeout="60" throwontimeout="no">
    <cfset StructClear(session)>
  </cflock>
 
<cflogin>
      <!--- IsDefined() makes sure form names exist. Display verification form (unless user is currently submitting it) --->
      <cfif IsDefined("FORM.pw") eq False or IsDefined("FORM.lastName") eq False>
         <cfinclude template="../teacher/ws_teacherLoginForm.cfm">
         <cfabort>
      </cfif>
      
<!--- email and password can not be null, miss any one will not be able to log in --->
      <cfif FORM.pw is "" or FORM.lastName is "">
            <!--- Display message and re-display login form --->
            <center>
            <font color="#FF0000"><b>Your Email Address and Password are required to enter E-learning Project.</b></font>
            <hr width="450">
            </center>
            <cflock throwontimeout="no" timeout="60">
            <cfset SESSION.show_up = 1>
            </cflock>
            <cfinclude template="../teacher/ws_teacherLoginForm.cfm">
            <cfabort>
      </cfif>

      <!--- Attempt to find pw in database --->
      <cfquery name="UserQuery" datasource="aptvre">
            SELECT * FROM ws_teacher
            WHERE teacherLastName = '#FORM.lastName#' AND pw = '#FORM.pw#'
      </cfquery>
      <!--- If the user was found in database --->
      <cfif UserQuery.RecordCount GT 0>
            <!--- Tell CouldFusion to consider user to be logged in --->
            <cfloginuser name="#FORM.lastName#" password="#FORM.pw#" roles="">
            <cflock throwontimeout="no" timeout="60">
                  <cfset SESSION.teacher_name = #UserQuery.TeacherFirstName#&' '&#UserQuery.TeacherLastName#>
                  <cfset SESSION.teacherID = #UserQuery.teacherID#>
                  <cfset SESSION.projectID = 1>
            </cflock>
      <cfelse>
            <!--- Display message and re-display login form --->
            <cflock throwontimeout="no" timeout="60">
            <cfset SESSION.show_up = 1>
            </cflock>
            <center>
            <font color="#FF0000"><b>Your Email Address and Password are incorrect!</b></font>
            <hr width="450">
            </center>
            <cfinclude template="../teacher/ws_teacherLoginForm.cfm">
            <cfabort>
      </cfif>
</cflogin>
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

19 Experts available now in Live!

Get 1:1 Help Now