Advertisement

03.20.2008 at 08:30AM PDT, ID: 23257233
[x]
Attachment Details

Help with Undefined Variable

Asked by NorthDorsetWeb in WebApplications, Microsoft Access Database, Active Server Pages (ASP)

Tags: ASP VBScript, IIE

I was given some help on here a while ago setting up an authentication for users to log onto a site.   I have used this code to successfully set up a number of sites but i seem to be having a problem with this site in particular.  Granted this is using a slightly more sophisticated menu system and it has breadcrumbs but the pages that seem to be affected were based on the original page.  

Bascially the error im getting is a database erorr stating that a variable is undefined.  I had this problem before which i ran through with the last expert that helped me - and i found the problem - i have done the same investigating but cant seem to find it anywhere.  Can anyone help me?

The site is at www.emmagale.info  -  the username is testuser the password is testuser.  By the way the current content does not reflect the final use - i have just cobbled together information from a few sites i have done in the past.





Here is the authlib code:

<%

      ' This points to your login page.  It will be used in automatic redirections
      Const C_LOGIN_PAGE_URL = "../logon.asp"

' --------------------------------------
' -- Login User
' --------------------------------------
Function LoginUser
      Dim objConn
      Dim objCmd
      Dim objRecSet
      Dim objParam
      Dim objErr
      Dim strUsername
      Dim strPassword
      Dim strMemberID
      Dim strError

      ' Default to failure
      strError     = "ERR_INVALID"
      strUsername  = Request.Form("username")
      strPassword  = Request.Form("password")

      ' If for some reason this user is logged in, close the session
      Session.Contents.RemoveAll()

      If (strUsername = "") OR (strPassword = "") Then Exit Function

      ' Ignore errors when they happen so that we can detect them manually
      On Error Resume Next

      ' Initialize the Connection and Command objects
      '
      ' Use a command object instead of a RecordSet object.
      ' The command object will return a recordset.
      Set objConn = Server.CreateObject("ADODB.Connection")
      Set objCmd  = Server.CreateObject("ADODB.Command"   )

      ' Initialize the connection
      '   -----
      '   NOTE:  I assume MM_conFamily_STRING is a valid connection string
      '   -----
            objConn.CursorLocation    = adUseServer
            objConn.ConnectionString  = MM_conPHIN_STRING
            objConn.ConnectionTimeout = 30
            objConn.CommandTimeout    = 30
            objConn.Open MM_conPHIN_STRING

      ' Continue if the connection is active
      If (objConn.State <> adStateClosed) Then
            ' Initialize the command
                  objCmd.ActiveConnection = objConn
                  objCmd.CommandText      = "SELECT *  FROM tblMembers  WHERE Username=? AND Password=?"

            ' Initialize the parameters
            ' Username
            Set objParam = objCmd.CreateParameter("Username")
                  objParam.Type      = adVarChar
                  objParam.Value     = strUsername
                  objParam.Direction = adParamInput
                  objParam.Size      = Len(strUsername)
            objCmd.Parameters.Append objParam

            ' Password
            Set objParam = objCmd.CreateParameter("Password")
                  objParam.Type      = adVarChar
                  objParam.Value     = strPassword
                  objParam.Direction = adParamInput
                  objParam.Size      = Len(strPassword)
            objCmd.Parameters.Append objParam

            Set objParam = Nothing

            ' Execute the query and get the record set
            objCmd.Prepared = True
            Set objRecSet = objCmd.Execute( , , adCmdText)

            ' Check to see if there were any errors
            If (Err.Number <> 0) OR (objConn.Errors.Count > 0) Then
               ' and error occurred! handle it!
               ' you may want to loop through the Errors
               ' collection to discover them

                  strError = "ERR_DBCMD"
                          'This is commented out now and only should be used if there is an error
                          Response.Write "ASP ERROR:[" & Err.Description & "]<br>"
                          Response.Write "DB ERROR:[" & objConn.Errors(0).Description & "]<br>"

            ElseIf NOT (objRecSet.BOF AND objRecSet.EOF) Then
                  strMemberID = objRecSet("MemberID")

                  If (strMemberID <> "") Then
                        ' We found the user!
                        strError = ""

                        ' Initialize the Authorized Session.
                        ' You may want to store other user information here
                        Session("AUTH_USER") = strMemberID

                        ' Preferrably, you would store an encrypted token
                        ' which would then be also sent as a cookie and
                        ' then validated on each request.
                  End if
            End If

            objRecSet.Close()
            objConn.Close()
      Else
            ' You may want to log these errors.

            strError = "ERR_DBCONN"
      End If

      set objRecSet = Nothing
      set objCmd    = Nothing
      set objConn   = Nothing

      ' Disable ignore errors
      On Error Goto 0

      LoginUser = strError
End Function

' --------------------------------------
' -- Logout User
' -------------------------------------
Sub LogoutUser
      ' If you set an Auth Cookie, you should delete it here

      ' Clear the session
      Session.Abandon()
      RedirToLogin "ERR_LOGOUT"
End Sub

' --------------------------------------
' -- Redirect to Login Screen
' --------------------------------------
Sub RedirToLogin(ByVal strErrCode)
       'DEBUG:  This line has now been commented
     Response.Redirect(C_LOGIN_PAGE_URL & "?error=" & strErrCode)
End Sub

' --------------------------------------
' -- Authenticate Session
' --------------------------------------
Sub AuthenticateSession
      Dim strAuthUser

      strAuthUser = Session("AUTH_USER")

      ' If you set an Auth Cookie you should decrypt it and
      ' validate it here against the token stored in the session.

      If (strAuthUser = "") Then
            Session.Abandon()
            RedirToLogin "ERR_SESSION"
      End If
End Sub
%>

Here is the logon page code:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% Option Explicit %>
<!--#include file="Connections/conPHIN.asp" -->
<% Session.LCID = 2057 'English regional setttings %>
<!-- #include virtual="auth_lib.asp" -->

<%
Dim ERROR_CODE : ERROR_CODE = ""

      ' Check if the login form was submitted (i.e. the button was clicked)
      If Request.Form("btnLogin") <> "" Then
            ERROR_CODE = LoginUser()

            ' Login succeeded, redirect to main page!
            If ERROR_CODE = "" Then
                  Response.Redirect("index.asp")
            End If
      Else
            ' Get the error code from the query string (if any)
            ERROR_CODE = Request.QueryString("error")
      End If

%>
<?xml version="1.0" encoding="iso-8859-1"?>
<!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"><!-- #BeginTemplate "/Templates/template.dwt" --><!-- DW6 -->
<head>
<!-- #BeginEditable "title" -->
<title>Healthcare Inside |  Supporting the delivery of Prison Healthcare</title>
<meta name="Keywords" content="Healthcare Inside, PHIN, Centre of Innovation, Prison, Prisoners, Healthcare" lang="en" xml:lang="en" />
<meta name="Description" content="Healthcare Inside supports the delivery of Prison healthcare" />
<meta name="DC.subject" content="Healthcare Inside brought to you by the Prison Health Innovation Network" lang="en" xml:lang="en" />
<meta name="DC.description" content="Healthcare Inside supports the delivery of Prison healthcare" lang="en" xml:lang="en" />
<!-- #EndEditable -->
<!-- #include virtual="incs/head.htm" -->
<!-- #include virtual="incs/breadcrumb.asp" -->
</head>
<body>
<div id="container">
<h1>Healthcare Inside</h1>    
<!-- #include virtual="incs/search.htm" -->
<!-- #include virtual="incs/menu.htm" -->
<!-- Begin Content on the RIGHT -->
<div id="content"><a name="skipnav" id="skipnav" />
<div id="crumbs"><% = BreadCrumb(Replace(Request.ServerVariables("PATH_INFO"),"main/","")) %></div>
<!-- #BeginEditable "heading" -->
<h2>Logon Page</h2>
<!-- #EndEditable -->  
<!-- #BeginEditable "content" -->
  <p align="center">
          <%
      Dim strErrorMsg

      ' After authentication, dispay an error if necessary

      If ERROR_CODE <> "" Then
            ' Display user-friendly errors based on the error code
          Select Case ERROR_CODE
              Case "ERR_INVALID"
                    strErrorMsg = "Invalid username or password.  Please try again."
              Case "ERR_DBCMD"
                    strErrorMsg = "A database error occurred."
              Case "ERR_DBCONN"
                    strErrorMsg = "Error connecting to the database."
              Case "ERR_SESSION"
                    strErrorMsg = "Invalid or expired session.  Please log in."
              Case "ERR_LOGOUT"
                    strErrorMsg = "Your session has been terminated.  Enter your username and password to log-in again"
              Case Else
                    strErrorMsg = "Unknown error.  Please contact administrator."
          End Select

          ' Display the error message
          Response.write ("<font color='red'><b>" & strErrorMsg & "</b></font>")
      End If
%>
          </p>
        <p align="center">Please enter your username and password below: </p>
        <form action="logon.asp" method="POST">
          <table width="500" border="0" align="center" cellpadding="4" cellspacing="0">
              <tr>
                <td><strong>Login</strong>:</td>
                <td><input type="text" name="username" value=""></td>
              </tr>
              <tr>
                <td><strong>Password</strong>:</td>
                <td><input type="password" name="password" value=""></td>
              </tr>
              <tr>
                <td></td>
                <td><input type="submit" name="btnLogin" value="Login"></td>
              </tr>
          </table>
      </form>
<!-- #EndEditable --></div>
<!-- End Content on the RIGHT -->
</div>
<!-- #include virtual="incs/footer.htm" -->
</body>
<!-- #EndTemplate --></html>

Is there anything else i should provide?
Start Free Trial
 
Loading Advertisement...
 
[+][-]03.20.2008 at 08:49AM PDT, ID: 21172735

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.20.2008 at 08:53AM PDT, ID: 21172777

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.20.2008 at 09:04AM PDT, ID: 21172888

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.20.2008 at 09:18AM PDT, ID: 21173016

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.20.2008 at 09:46AM PDT, ID: 21173284

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: WebApplications, Microsoft Access Database, Active Server Pages (ASP)
Tags: ASP VBScript, IIE
Sign Up Now!
Solution Provided By: hielo
Participating Experts: 2
Solution Grade: A
 
 
[+][-]03.21.2008 at 11:32AM PDT, ID: 21182056

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.25.2008 at 10:50AM PDT, ID: 21204262

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.25.2008 at 01:55PM PDT, ID: 21206089

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.25.2008 at 03:13PM PDT, ID: 21206762

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.10.2008 at 07:20AM PDT, ID: 21539126

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628