秘密行动组在线看高清:来看看这一小段ASP代码吧

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/30 10:06:07
让真正的管理员操作后台管理员页,可通过这段代码实现;但是我不太了解这段代码的含义,谁能抽空帮忙讲一下,谢谢!

<%if session("admin")="" then
response.Write "<script language='javascript'>alert('网络超时或您还没有登陆!');window.location.href='login.asp';</script>"
response.End
else
if session("flag")=2 then
response.Write "<p align=center><font color=red>您没有此项目管理权限!</font></p>"
response.End
end if
end if
%>

此代码不是太长,尽量说的详细点吧!如
session("admin")="" 什么意思,与数据库什么联系.....................

这样的代码只有这一个么,有没其他的?如果有,有什么区别?

<%if session("admin")="" then
response.Write "<script language='javascript'>alert('网络超时或您还没有登陆!');window.location.href='login.asp';</script>"
response.End
----------------------------------------------session的意思是浏览你网页的那台机器上的记录,与数据库没有什么关系.你可以去百度详细查一下"session"的意思,admin是自定义的,这句话的意思是:如果session值admin等于空 那么用javascript语言弹出一个对话框"网络超时或您还没有登陆!" 但是你上面的代码有一个错误 那就是"response.end"这句不应该写 "response.end"写上了 下面的程序就不能运行了.
------------------------------------------------
else
if session("flag")=2 then
response.Write "<p align=center><font color=red>您没有此项目管理权限!</font></p>"
response.End
------------------------------------------------
接着上面语言:否则(else)如果session值flag=2那么输出文字"您没有此项目管理权限!"在这里说名一下FLAG应该是检查你是不是管理员,如果是那 SESSION(FLAG)=1就表明你有管理权限否则=2,就没有管理权限。这里的那个错误依然存在 就是不要用"response.end"
------------------------------------------------
end if
end if
%>
-----------------------------------------------
这里就不用我说了吧!
总体来说你这是一个后台登陆页面的验证代码的一部分.我讲这么多不知道满意不?

session("admin")="" :这是存在SESSION里的SESSION变量,在整个会话中可见,ADMIN可能是数据库的用户名,要看ADMIN定义的地方代码怎么定义的。

这里更象登陆用的用户名,如果用户名为空,就转到登陆页面'login.asp'

FLAG应该是标定是不是管理员,如果是那
SESSION(FLAG)=1否则=2,就没有管理权限。

<%
session("login")="yes"
%>
这句话的意思就是在session里面定义一个login字符串变量,值为"yes",直接可以赋值,不需要声明。是不是很简单?

如果我们做管理员登陆系统的话,首先是一段检测是不是管理员:

if 是 then
session("isadmin")=yes"
else
session("isadmin")="no"
end if
在每一个需要管理员才能看的页面最前面加上:

<%
if not session("isaadmin")="yes" then
response.redirect "login.htm"
%>
这样一般用户就无法打开这个页面。解释一下response.redirect,它是转向的意思,后面的"login.htm"就是转向的文件。这样没有登陆的管理员是无法看到后面的内容的。

response组件基本就是用到response.write(),response.redirect() 分别是写字符串和转向的作用。

request基本就是request.form(),request.querystring() 分别是接受post,get方法传来的信息。

最后我们一起来制作一个简单的后台登陆管理界面,首先在myweb目录下建立一个admin文件夹,然后我们建立一个数据库名字为admin.mdb,然后我们再建立一个表,表中设置两个字段name,password,类型都是文本型的!最后退出时设置主键,保存为表名check。然后可以输入一条记录用户名:admin,密码:admin。具体建立数据库的方法请看《菜鸟十天学会ASP教程之第三天:数据库的建立》

下面我们开始编写ASP程序,首先建立一个index.asp(管理主界面)程序,代码如下:

<%@language=vbscript%>
<%if not session("checked")="yes" then
response.Redirect "login.asp"
else
%>
<html>
<head>
<title>管理界面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<frameset cols="167,*" frameborder="YES" border="1" framespacing="1" rows="*" bordercolor="#666666">
<frame name="leftFrame" scrolling="auto" noresize src="left.asp">
<frame name="mainFrame" src="right.asp">
</frameset>
<noframes>
<body bgcolor="#FFFFFF" text="#000000">
</body>
</noframes>
</html>
<%end if%>

在上面的代码中,大家可以看到用到login.asp,left.asp,right.asp程序

login.asp://登陆系统程序

<html>
<head>
<title>管理员入口</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.topic { font-family: "宋体"; font-size: 11pt; font-weight: bold; color: #FFFFFF}
.font { font-family: "宋体"; font-size: 10pt; font-weight: normal; color: #000000}
.table { border-color: #666666 black; border-style: solid; border-top-width: 1pt; border-right-width: 0px; border-bottom-width: 1pt; border-left-width: 0px}
.text { border: 1pt #999999 solid; height: 15pt}
-->
</style>
</head>

<body text="#000000" topmargin="0" bgcolor="#FFFFFF">
<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" height="100%">
<tr>
<td height="129" valign="top" colspan="3">  </td>
</tr>
<tr>
<td width="230" height="170" valign="top"> </td>
<td valign="top" width="277">
<table width="100%" border="0" cellspacing="1" cellpadding="0" height="100%" bgcolor="#000000" align="center">
<tr>
<td align="center" valign="middle" height="167">
<form name="form1" method="post" action="check.asp">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
<tr bgcolor="#62892C">
<td height="31" class="topic" colspan="2">
<div align="center">管理员入口<br>
</div>
</td>
</tr>
<tr>

<td bgcolor="#87bc3c" colspan="2" class="table">
<div align="center"> <span class="font"> 管理员:</span>
<input type="text" name="name" class="text" size="20" onMouseOver="this.focus()">
<br>
<span class="font">密 码:</span>
<input type="password" name="password" class="text" size="20" onMouseOver="this.focus()"><%if session("check")="wrong" then response.Write "<br><span class='font'><font color=red>验证错误!</font></span>" end if%>
</div>
</td>

</tr>
<tr>
<td bgcolor="#87bc3c" width="52%">
<div align="center" class="font">
<input type="reset" name="Submit2" value="重置" class="text">
</div>
</td>
<td bgcolor="#87bc3c" width="48%">
<div align="center" class="font">
<input type="submit" name="Submit22" value="提交" class="text">
</div>
</td>
</tr>
</table> </form>
</td>
</tr>
</table>
</td>
<td width="241" valign="top"> </td>
</tr>
<tr>
<td height="123" valign="top" colspan="3"> </td>
</tr>
</table>
</body>
</html>

在上面的程序中用到一个检查用户和密码是否正确的程序check.asp://核对输入的用户和密码是否正确

<%
dim name,password
name=request.form("name")
password=request.form("password")
dim exec,conn,rs
exec="select *from check where(name='"&name&"' and password='"&password&"')"
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("admin.mdb")
set rs=server.createobject("adodb.recordset")
rs.open exec,conn
if not rs.eof then
rs.Close
conn.Close
session("checked")="yes"
session("check")="right"
response.Redirect "index.asp"
else
session("checked")="no"
session("check")="wrong"
response.Redirect "login.asp"
end if
%>

left.asp://管理导航

<%@language=vbscript%>
<%if not session("checked")="yes" then
response.Redirect "login.asp"
else
%>
<html>
<head>
<title>管理界面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body text="#000000" topmargin="0" bgcolor="#ffffff" leftmargin="10">
<div align="center"><a href="index.asp" target="_parent"><br>
<br>
管理界面首页</a> <a href="exit.asp" target="_parent">退出</a><br>
<br>
</div>
</body>
</html>
<%end if%>

exit.asp://退出系统

<%@language=vbscript%>
<%
session("check")=""
session("checked")=""
response.redirect "login.asp"
%>

right.asp://具体管理的内容

<%@language=vbscript%>
<%if not session("checked")="yes" then
response.Redirect "login.asp"
else
%>
<html>
<title>管理界面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#ffffff" text="#000000" topmargin="20" class="title">

这里是网页教学网的管理系统示例!请大家多研究使用!
</body>
</html>
<%end if%>