用户登录失败后不能返回登录页面 [已解决,谢谢您的关注!]
登录成功后,能成功返回首页(index.asp)
可登录失败后,却不能返回此登录页面(yhdl.asp),仍停留在登录执行页面(yhdlzx.asp)(空白)
请各位老师在下面的代码中帮学生改一改吧!多谢!
登录页面:yhdl.asp
<table width="800" height="30" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><form action="yhdlzx.asp" method="post" name="form1" target="_blank" id="form1">用户名:
<input name="name" type="text" id="name" size="15">
密码:
<input name="pwd" type="password" id="pwd" size="15">
<input type="submit" name="Submit" value="登 录">
注 册
</form></table>
登录执行页面:yhdlzx.asp
<!--#include file="../conn.asp" -->
<%
Session("name")=request.form("name")'在 Session中保存用户名
dim username,password
name=request.form("name")'从表单传递的用户名
pwd=request.form("pwd")
'查询记录
set rs=server.CreateObject("adodb.recordset")
sql="select * from yhgl where name='"&name&"'"
rs.open sql,conn,1,1
if rs.eof then
response.write "<script>alert('登录失败,用户名不对');history.back();</script>"
response.end
else
Session("MM_Username") = MM_valUsername
if rs("pwd")<>pwd then
response.write "<script>alert('登录失败,密码不对');history.back();</script>"
response.end
end if
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString<>"" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)
MM_valUsername=CStr(Request.Form("name"))
If MM_valUsername <> "" Then
MM_fldUserAuthorization="yhjb"
MM_redirectLoginSuccess="../index.asp"....登录成功后,能成功返回首页
MM_redirectLoginFailed="yhdl.asp".........可登录失败后,却不能返回此登录页面,仍停留在登录执行页面(yhdlzx.asp)
MM_flag="ADODB.Recordset"
set MM_rsUser = Server.CreateObject(MM_flag)
MM_rsUser.ActiveConnection = conn
MM_rsUser.Source = "SELECT name, pwd"
If MM_fldUserAuthorization <> "" Then MM_rsUser.Source = MM_rsUser.Source & "," & MM_fldUserAuthorization
MM_rsUser.Source = MM_rsUser.Source & " FROM yhgl WHERE name='" & Replace(MM_valUsername,"'","''") &"' AND pwd='" & Replace(Request.Form("pwd"),"'","''") & "'"
MM_rsUser.CursorType = 0
MM_rsUser.CursorLocation = 2
MM_rsUser.LockType = 3
MM_rsUser.Open
If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then
' username and password match - this is a valid user
Session("MM_Username") = MM_valUsername
Session.Timeout = 120
If (MM_fldUserAuthorization <> "") Then
Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
Else
Session("MM_UserAuthorization") = ""
End If
if CStr(Request.QueryString("accessdenied")) <> "" And false Then
MM_redirectLoginSuccess = Request.QueryString("accessdenied")
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginSuccess)
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginFailed)
session("admin")=username
End If
End If
conn.close '关闭连接,
set conn=nothing '释放内存 这两句很重要,不然会占用大量服务器资源
%>
[ 本帖最后由 tepnidh 于 2012-2-3 11:25 编辑 ]