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]