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" %>
注:更多精彩教程請關注三聯網頁設計教程 欄目,