manage.asp
' 登录页面.
<%@ Language=VBScript %>
<html>
<body>
<form name="Login" method="Post" action="login.asp">
<input type="text" name="username" size="20">用户名<br>
<input type="password" name="password" size="20">口令<br>
<input type="submit" name="btnLogin" value="登录">
</form>
</body></html>
login.asp
' 验证在表单中输入的用户名和口令.
<%@ Language=VBScript %>
<% Response.Buffer = True %>
<html>
<body>
<% Session("allow") = True %>
<%
UserName = Request.Form("username")
Password = Request.Form("password")
' 抓取表单内容.
Set MyConn=Server.CreateObject("ADODB.Connection")
MyConn.Open "连接字符串"
SQL = "Select * From tblLogin"
Set RS = MyConn.Execute(SQL)
If UserName = RS("UserName") AND Password = RS("Password") Then
' 如果匹配则显示要保护的页面.
%>
----------------------------------------------------------------------------------------------------------------
' 此处放置要保护的页面的内容.
----------------------------------------------------------------------------------------------------------------
<%
Else
Response.Redirect "http://www.intels.net/login.asp"
RS.Close
MyConn.Close
Set RS = Nothing
Set MyConn = Nothing
End If
%>
' 如果不匹配则返回登录页,让用户重新登录.
</body></html>
好了,让我们来做最后的应用工作吧,把下面的代码加入需要保护的页面的最前面:
<%@ Language=VBScript %>
<% Response.Buffer = True %>
<% If session("allow") = False Then Response.Redirect "manage.asp" %>
[1]