初學ASP的人對session一直不是很了解. 我這只cai鳥就在這談談在做簡單後台登陸時session的簡單使用: 武林網小編給您推薦這個ASP編程中利用session製作一個管理登陸頁的實例代碼,這裡還有關於ASP編程session 管理登陸頁的教程,希望您能夠喜歡並學到東西提升自己的知識與技能,下面是內容詳細閱讀:
一: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>
本頁網址:http://www.VeVb.com/biancheng/a/2018091514119.shtml,如果對您有幫助歡迎收藏或轉載網址,歡迎再次訪問http://www.VeVb.com!