怎么用ASP实现用户权限问题,让不同的用户登录到不同的页面,请教高手!
我要做一个用户登录系统,我想让不同的用户登录到不同的页面里,比如用户名为1的进入1.asp,用户名为2的进入2.asp 以此类推。请高手帮忙修改一下我的登录代码,谢谢!数据库有一个zhi_rui_e_manage表用来放用户信息:
表中的字段如下:
我的登录页面Login.asp的代码如下:
程序代码:
<!--主要是使随机出现的产品数字随机--> <% Response.Expires = -1 Response.ExpiresAbsolute = Now() - 1 Response.Expires = 0 Response.CacheControl = "no-cache" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.> <html xmlns="http://www.> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>管理员登陆</title> <link href="images/style_left.css" type=text/css rel=stylesheet> <SCRIPT type=text/javascript> <!-- if(self!=top){top.location=self.location;} function ShowSoftKeyboard(obj) { if((typeof(CheckLoaded) == "function")) { password1 = obj; showkeyboard(); Calc.password.value = ''; } else { return false; } } // --> </SCRIPT> <SCRIPT src="images/softkeyboard.js" type=text/javascript></SCRIPT> </head> <BODY id=loginbody> <form name="AdminLogin" method="post" action="Cklogin.asp"> <DIV id=adminboxall> <DIV class=adminboxtop></DIV> <DIV id=adminboxmain> <div style=" margin-left:380px; margin-top:5px;"> <INPUT id=IbtnEnter style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; WIDTH: 76px; HEIGHT: 26px; BORDER-RIGHT-WIDTH: 0px" type=image src="images/admin_menu.gif" name=IbtnEnter> </div> </DIV> <DIV class=adminboxbottom> <DIV id=login> <UL> <LI class=text>用户名:<BR> <DIV class=box1><input class=smallInput name="LoginName" type="text" id="LoginName" Style="width:80px;"></DIV></LI> <LI class=text>密 码:<BR> <DIV class=box2><input class=smallInput name="LoginPassword" type="password" id="LoginPassword" Style="width:80px;"></DIV></LI> <LI class=text>验证码:<BR> <DIV class=box4> <input class=smallInput name="code" type="text" id="code" size="8" maxlength="5"/> <img src="Code.asp" border="0" alt="看不清楚请点击刷新验证码" onClick="this.src='code.asp'"/> </DIV></LI> </UL> </DIV> </DIV> </DIV> </FORM> </BODY> </html>
输入用户名,密码后转跳到Cklogin.asp页面进行验证,代码如下:
程序代码:
<!--#include file="Conn.asp"--> <!--#include file="md5.asp"--> <% dim LoginName,LoginPassword,AdminName,Password,AdminPurview,Working,UserName,rs,sql,mycode LoginName=trim(request.form("LoginName")) LoginPassword=Md5(request.form("LoginPassword")) mycode = trim(request.form("code")) set rs = server.createobject("adodb.recordset") sql="select * from zhi_rui_E_manage where AdminName='"&LoginName&"'" rs.open sql,conn,1,3 if rs.eof then response.write "<script language=javascript> alert('管理员名称不正确,请重新输入。');location.replace('Login.asp');</script>" response.end else AdminName=rs("AdminName") Password=rs("Password") AdminPurview=rs("AdminPurview") Working=rs("Working") UserName=rs("UserName") end if if LoginPassword<>Password then response.write "<script language=javascript> alert('管理员密码不正确,请重新输入。');location.replace('Login.asp');</script>" response.end end if if mycode<>Session("getcode") then response.write "<script language=javascript> alert('您输入验证码错误,请返回重新登录!');location.replace('Login.asp');</script>" response.end end if if Working=0 then response.write "<script language=javascript> alert('不能登录,此管理员帐号已被锁定。');location.replace('Login.asp');</script>" response.end end if if LoginName=AdminName and LoginPassword=Password then rs("LastLoginTime")=now() rs("LastLoginIP")=Request.ServerVariables("Remote_Addr") rs.update rs.close set rs=nothing session("ZhiRui_Admin")=AdminName session("ZhiRui_User")=UserName Session("ZhiRui_Ck")="ZhiRuiAdmin" Session.Timeout = 60 session("AdminPurview")=AdminPurview Response.Cookies("ZhiAdmin")="" '================================== dim LoginIP,LoginTime,LoginSoft LoginIP=Request.ServerVariables("Remote_Addr") LoginSoft=Request.ServerVariables("Http_USER_AGENT") LoginTime=now() '==================================== set rs = server.createobject("adodb.recordset") sql="select * from zhi_rui_E_manageLog" rs.open sql,conn,1,3 rs.addnew rs("AdminName")=AdminName rs("UserName")=UserName rs("LoginIP")=LoginIP rs("LoginSoft")=LoginSoft rs("LoginTime")=LoginTime rs.update rs.close set rs=nothing '======================================== response.redirect "index.asp" response.end end if %> </BODY> </html>
请高手帮忙修改,谢谢!