一:login.htm
這個頁面我就不多說了 加上表單 寫上管理員昵稱 給出文本框username
寫上密碼 給出文本框userpass 再加一個提交按扭即可. 注:表單的action為chklogin.asp
二:chklogin.asp
<!--#include file="conn.asp"-->
<%set rs=server.CreateObject("adodb.recordset")
sql="select * from admin where username='"&request.Form("username")&"'"
'其中admin為存貯管理員帳號和密碼的表名
rs.open sql,con,1,1
%>
<%if rs.eof then
response.Write"沒有這個管理員"
else
%>
<%
username=trim(request.Form("username"))
password=request.Form("password")
%>
<%if password=rs("userpass") then
session("admin")="ercifang"
response.Redirect("manage.asp")
else
response.Write"本頁為管理員專用頁面"
end if
%>
<%end if%>
看紅色的文字,這樣就為管理員添加的了一個session
在manage.asp中第一行設置
<%if session("admin")="ercifang" then
……
else
response.write"只有管理員才能進入本頁面"
end if%>
這樣,其他人直接訪問manage.asp時就不能對本站進行管理了。
下面再給出login.htm的代碼:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>管理登陸</title>
<style type="text/css">
.fengge{font-size:12px}
</style>
</head>
<body>
<form name="form1" method="post" action="chklogin.asp">
<table width="400" border="1" align="center" class="fengge">
<tr>
<td width="129"> </td>
<td width="255"> </td>
</tr>
<tr>
<td><div align="right">管理員名稱:</div></td>
<td><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td><div align="right">管理密碼:</div></td>
<td><input name="password" type="password" id="password"></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit" value="重置">
</td>
</tr>
<tr>
<td colspan="2"><div align="right"></div></td>
</tr>
</table>
</form>
</body>
</html>
新聞熱點
疑難解答