Control | page | source code
We usually want to set up a user login system in the production site, that is, when users can see the corresponding content after landing, this method is often used, the specific implementation of the flowchart:
The specific ASP source code is as follows: (including 3 files)
Login.asp
<%@ language= "VBScript"%>
<% Option Explicit%>
<% Response.Buffer = True%>
<!--#include file= "dbconn.asp"-->
<%
'================================================
' Was the ' form submitted?
' If So, lets check the Username and Password
'================================================
If Request.Form ("submitted") = "Login" Then
' Declare Our variables
Dim objconn, objRS, strSQL
' Create Connection Object
Set objconn = Server.CreateObject ("ADODB. Connection ")
objConn.Open strconnect
' Build SQL String
strSQL = "SELECT * from MemberInfo WHERE username= '" & Request.Form ("Username") & ""
' Create Recordset Object
Set objRS = Server.CreateObject ("ADODB. Recordset ")
Objrs.open strSQL, objconn
If objrs.eof Then
'================================================
' Does the Username exist?
' If not, set strfailed and destroy all objects.
' We ' ll then display the login form again.
'================================================
strfailed = "Invalid Username"
Objrs.close
Set objRS = Nothing
Objconn.close
Set objconn = Nothing
Else
'================================================
' Username exists-is the password correct?
' If not, set strfailed and destroy all objects.
' We ' ll then display the login form again.
'================================================
If objrs.fields ("Password") <> Request.Form ("Password") Then
strfailed = "Invalid Password"
Objrs.close
Set objRS = Nothing
Objconn.close
Set objconn = Nothing
Else
'================================================
' Username and password are valid.
' Set session variable.
' Destroy all objects.
' Redirect to Secret page
'================================================
Session ("ValidUser") = "true"
Objrs.close
Set objRS = Nothing
Objconn.close
Set objconn = Nothing
Response.Redirect "Secret-page.asp"
End If
End If
End If
%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en"
"Http://www.w3.org/TR/html4/strict.dtd" >
<title> Member Login System </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body>
If strfailed <> "" Then
Response.Write "<p>" & strfailed & "</p>" & VbCrLf
End If
%><form method= "POST" action= "Login.asp" >
<p>
<label for= "username" > Username:</label>>
<input type= "text" id= "username name=" username ">
</p>
<p>
<label for= "password" > Password:</label>
<input type= "password" id= "password" name= "password" >
</p>
<p>
<input type= "Submit" Name= "submitted" value= "Login" >
</p>
</form>
</body>
Dbconn.asp
<%
' Declare Our variables
Dim Strdbvirtualpath, Strdblocation, strconnect
Strdbvirtualpath = "Memberdb/logininfo.mdb"
Strdblocation = Server.MapPath (Strdbvirtualpath)
strconnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & strdblocation
Response.Write Chr (13)
%>
Secret-page.asp
<%@ language= "VBScript"%>
<% Option Explicit%>
<% Response.Buffer = True%>
<%
'=====================================
' is the session variable ' ValidUser '
' Set to ' true '? -If not, redirect to
' Login.asp
'=====================================
If session ("ValidUser") <> "true" Then
Response.Redirect "Login.asp"
End If
%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en"
"Http://www.w3.org/TR/html4/strict.dtd" >
<title>secret area</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body>
<p>
Welcome to the secret area.
</p>
</body>