小弟第一次做權限問題,經過很多人的幫助終于作了一個 呵呵 特發布在這里 希望各位大蝦門指教 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 %>
呵呵 第一次原創文章 還真不習慣 多多提意見呀!
|