📄 admin_admin.asp
字号:
<!--#include file="config.asp"-->
<!--#include file="conn.asp"-->
<!--#include file="code.asp"-->
<!--#include file="inc/md5.asp"-->
<%
'检查管理员是否登录
AdminName = ReplaceBadChar(Trim(Request.Cookies(webkey)("AdminName")))
AdminPassword = ReplaceBadChar(Trim(Request.Cookies(webkey)("AdminPassword")))
RndPassword = ReplaceBadChar(Trim(Request.Cookies(webkey)("RndPassword")))
If AdminName = "" Or AdminPassword = "" Or RndPassword = "" Then
Response.Redirect "Admin_login.asp"
End If
%>
<%
if request("action")="add" then
call add()
elseif request("action")="edit" then
call edit()
elseif request("action")="del" then
call del()
elseif request("action")="saveadd" then
call saveadd()
elseif request("action")="saveedit" then
call saveedit()
else
call userlist()
end if
%>
<html>
<head>
<title>管理员管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="image/css.css" rel="stylesheet" type="text/css">
<script language=javascript>
function ConfirmDel()
{
if(confirm("确定要删除此管理员吗?"))
return true;
else
return false;
}
</script>
<body leftMargin=0 bgcolor="#EFEFEF" topMargin=15>
<%sub top()%>
<br>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#666666">
<tr>
<td height="25" bgcolor="#FFFFFF"> 管理员管理: <a href="admin_admin.asp" target="main">用户列表</a> <a href="admin_admin.asp?action=add" target="main">新增用户</a></td>
</tr>
</table>
<%end sub%>
<%
'管理员列表
sub userlist()
call top()
%>
<br>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#666666">
<tr align="center" bgcolor="#EFEFEF">
<td height="25"><strong>用户名</strong></td>
<td height="25"><strong>上次登录时间</strong></td>
<td><strong>上次退出时间</strong></td>
<td height="25"><strong>上次登陆IP</strong></td>
<td height="25"><strong>登陆次数</strong></td>
<td height="25"><strong>操作</strong></td>
</tr>
<%
dim rs, sql
Set rs=Server.CreateObject("Adodb.RecordSet")
sql="select * from "&AdminTable
rs.Open sql,conn,1,1
while not rs.EOF
%>
<tr align="center" bgcolor="#FFFFFF">
<td height="25"><%=rs("username")%></td>
<td height="25"><%=rs("LastLoginTime")%></span></td>
<td><%=rs("LastLogoutTime")%></td>
<td height="25"><%=rs("LastLoginIP")%></td>
<td height="25"><%=rs("LoginTimes")%></td>
<td height="25"><a href="admin_admin.asp?id=<%=rs("id")%>&action=edit">修改</a> <a href="admin_admin.asp?id=<%=rs("id")%>&action=del" onClick="return ConfirmDel();">删除</a></td>
</tr>
<%
rs.MoveNext
Wend
rs.close
set rs=nothing
call CloseConn()
%>
</table>
<%end sub%>
<%
'管理员添加
sub add()
call top()
%>
<br>
<form action="?action=saveadd" method=post>
<table width="350" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#666666">
<tr bgcolor="#EFEFEF">
<td width="100" height="25" align="center">用户名称:</td>
<td height="25" align="center">
<input name="username" type=text id="username" size=25>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="100" height="25" align="center">用户密码:</td>
<td height="25" align="center">
<input name="password" type="password" id="password" size=25>
</td>
</tr>
<tr bgcolor="#EFEFEF">
<td width="100" height="25" align="center">确认密码:</td>
<td height="25" align="center">
<input name="password2" type="password" id="password2" size=25>
</td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="25" colspan="2">
<input type="submit" name="Submit" value="添 加">
</td>
</tr>
</table>
</form>
<%end sub%>
<%
'管理员编辑
sub edit()
call top()
set rs = server.createobject("adodb.recordset")
sql="select * from "&AdminTable&" where id="&ReplaceBadChar(trim(request("id")))
rs.open sql,conn,1,1
if rs.eof and rs.bof then
rs.close
call closeconn()
response.write "<script>alert('此用户不存在');history.back()</script>"
else
%>
<br>
<form action="?action=saveedit&id=<%=ReplaceBadChar(trim(request("id")))%>" method=post>
<table width="350" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#666666">
<tr bgcolor="#EFEFEF">
<td width="100" height="25" align="center">用户名称:</td>
<td height="25" align="center">
<input name="username" type=text id="username" value="<%=rs("username")%>" size=25 disabled>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="100" height="25" align="center">用户密码:</td>
<td height="25" align="center">
<input name="password" type="password" id="password" size=25>
</td>
</tr>
<tr bgcolor="#EFEFEF">
<td width="100" height="25" align="center">确认密码:</td>
<td height="25" align="center"><span class="forumrow">
<input name="password2" type="password" id="password2" size=25>
</span></td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="25" colspan="2"><span class="forumrow">
</span>
<input type="submit" name="Submit" value="修 改">
</td>
</tr>
</table>
</form>
<%
rs.Close
call closeconn()
end if
end sub
%>
<%
'保存新增加用户
sub saveadd()
dim username,password,password2
username=ReplaceBadChar(trim(request.form("username")))
password=ReplaceBadChar(trim(request.form("password")))
password2=ReplaceBadChar(trim(request.form("password2")))
if username="" then
response.write "<script>alert('用户名不能为空');history.back()</script>"
response.end
elseif password="" then
response.write "<script>alert('请输入用户密码');history.back()</script>"
response.end
elseif password2="" or password2<>password then
response.write "<script>alert('请确认用户密码');history.back()</script>"
response.end
end if
set rs = server.createobject("adodb.recordset")
sql="select * from "&AdminTable&" where username='"&username&"'"
rs.open sql,conn,1,1
if rs.eof and rs.bof then
rs.close
sql="select * from "&AdminTable
rs.open sql,conn,1,3
rs.AddNew
rs("username") = ReplaceBadChar(username)
rs("password") = md5(ReplaceBadChar(password),16)
rs("level") = 0
rs.Update
rs.Close
call closeconn()
response.Redirect "Admin_admin.asp"
else
rs.close
call closeconn()
response.write "<script>alert('此用户名已存在');history.back()</script>"
end if
end sub
'保存用户密码修改
sub saveedit()
dim password,password2
password=ReplaceBadChar(trim(request.form("password")))
password2=ReplaceBadChar(trim(request.form("password2")))
if password="" then
response.write "<script>alert('请输入用户密码');history.back()</script>"
response.end
elseif password2="" or password2<>password then
response.write "<script>alert('请确认用户密码');history.back()</script>"
response.end
end if
set rs = server.createobject("adodb.recordset")
sql="select * from "&AdminTable&" where id="&ReplaceBadChar(trim(request("id")))
rs.open sql,conn,1,1
if rs.eof and rs.bof then
rs.close
call closeconn()
response.write "<script>alert('此用户名不存在');history.back()</script>"
else
rs.close
rs.open sql,conn,1,3
rs("password") = md5(ReplaceBadChar(password),16)
rs.Update
rs.Close
call closeconn()
response.Redirect "Admin_admin.asp"
end if
end sub
'用户删除
sub del()
on error resume next
sql="delete from "&AdminTable&" where id="&ReplaceBadChar(trim(request("id")))
conn.execute sql
if err.Number<>0 then
err.clear
call closeconn()
response.write "<script>alert('数据库操作失败! ');history.back()"
else
finished
call closeconn()
response.Redirect "Admin_admin.asp"
end if
end sub
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -