小弟第一次做权限问题,经过很多人的帮助终于作了一个 呵呵 特发布在这里 希望各位大虾门指教 1:建数据库 name 用户名 pwd 密码 oskey 权限
2:对数据库操作 添加用户 <table width="760" border="0" align="center" cellpadding="0" cellspacing="0" height="1"> <tr> <td bgcolor="#FFFFFF" width="163" height="143" valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr bgcolor="#000000"> <td><img src="http://www.okasp.com/techinfo/images/dot.gif" width="1" height="1"></td> </tr> </table>
<table width="151" border="0" cellpadding="0" cellspacing="0"> <tr bgcolor="#DFDFDF"> <td width="131" height="2" bgcolor="#FFFFFF" class="unnamed2"> <div align="center" class="unnamed1"> 增 加 用 户</div> </td> <td width="20" height="2" align="right" valign="bottom" bgcolor="#FFFFFF"> </td> </tr> </table> <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td> <FORM METHOD=POST ACTION="UserADD.asp"> <div align="center"> <table width="98%" border="0" cellpadding="0" cellspacing="5"> <tr> <td> <div align="center"><font color="#FFFFFF">用 户 名: <br> <input type=text name=UserName2 size="15" class="smallInput"> </font></div> </td> </tr> <tr> <td> <div align="center"><font color="#FFFFFF">用 户 权 限: <br> <select name="select"> <option value="super">系统管理员</option> <option value="check">录入、审核</option> <option value="input">录入</option> </select> </font></div> </td> </tr> <tr> <td> <div align="center"><font color="#FFFFFF">密 码: <br> <input type=text name=Passwd2 size="15" class="smallInput"> </font></div> </td> </tr> <tr> <td> <div align="center"> <input type=submit value=增加 name="submit" class="smallInput"> <input type="submit" name="Submit" value="取消" class="smallInput"> </div> </td> </tr> </table> </div> </FORM></td> </tr> </table> </td> <td bgcolor="#FFFFFF" width="10" height="143"><img src="http://www.okasp.com/techinfo/images/dot1.gif" width="1" height="1"></td> <td width="606" height="143" colspan="2" align="right" valign="top"> <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><% SET DATABASE=Server.CreateObject("ADODB.connection") %> <p>用户列表<br><% rst.open "select * from password ",conn,1 if rst.EOF then response.write "没有栏目:(" else %>
<table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000"> <tr> <td width="8%" bgcolor="#FFFFFF"> <div align="center"><font color="#000000">ID号</font></div> </td> <td width="21%" bgcolor="#FFFFFF"> <div align="center"><font color="#000000">用户名</font></div> </td> <td width="18%" bgcolor="#FFFFFF"> <div align="center"><font color="#000000">密码</font></div> </td> <td width="30%" bgcolor="#FFFFFF"> <div align="center"><font color="#000000">权限</font></div> </td> <td width="23%" bgcolor="#FFFFFF"> <div align="center"><font color="#000000">删除</font></div> </td> </tr> <%do while NOT rst.EOF%> <tr bgcolor="#FFFFFF"> <td width="8%" align="center"><%=rst("id")%></td> <td width="21%" align="center"><%=rst("name")%></td> <td width="18%" align="center"><%=rst("Pwd")%></td> <td width="30%" align="center"><%=rst("oskey")%></td> <td width="23%" align="center"><font color="#FFFFFF"><a href="userdel.asp?id=<%=rst("id")%>&name=del">删除</a></font></td> </tr> <% rst.MoveNext loop end if rst.close %> </table> <p>系统管理员: super<br> 录入、审核员: check<br> 录入: input</p> </td> </tr> </table> <div align="center"><br> <a href="mimi.asp">back </a></div></td> </tr> </table>
添加用户 useradd.asp <!--#include file="articleconn.asp"--> <% dim rs,tsql dim rst set rst=server.CreateObject("ADODB.RecordSet")
rst.open "select * from password",conn,3,2 rst.addnew rst("oskey")=request("select") rst("name")=request("UserName2") rst("Pwd")=request("Passwd2") rst.update rst.close
response.redirect "usermanage.asp"%> 呵呵 时间原因 删除的原代码旧不写了
3: 很重要的一环就是下面了 各位应看的出来他的作用 chklogin.asp <!--#include file=articleconn.asp--> <% dim rs name=request.form("Name") pwd=request.form("pwd") set rs=server.createobject("adodb.recordset") rs.open "select * from password where name='" & name & "'",conn,1 if pwd<>rs("pwd") then response.write "<link rel='stylesheet' type='text/css' href='style.css'>" response.write "<body bgcolor='#ffffef'>" response.write "Sorry,请输入正确的管理员名字和密码" else session("UserName")=RS("name") session("KEY")=rs("OSKEY") response.redirect "mimi.asp" end if rs.close conn.close set rs=nothing set conn=nothing %>
4:下面就是在 你需要加权限的地方加上条件语句了 例如:<% IF Session("KEY")<>"super"THEN response.redirect "mimi.asp" response.end END IF %>
<% IF not(Session("KEY")="super" or session("KEY")="check" or Session("KEY")="input") THEN response.redirect "login.asp" response.end END IF %>
呵呵 第一次原创文章 还真不习惯 多多提意见呀!
|