+ -
当前位置:首页 → 问答吧 → asp登录界面。

asp登录界面。

时间:2011-09-18

来源:互联网

用asp做了一个网站的登录代码。
<!--#Include file="../func/conn.asp"-->
<%
dim UserName,Password
UserName=trim(request("UserName"))
Password=trim(request("Password"))

if UserName="" then
response.Write(" <script>alert('Your username is blank!');history.go(-1); </script>") 
end if
if Password="" then
response.Write(" <script>alert('Your password is blank!');history.go(-1); </script>") 
end if

set rs=server.createobject("adodb.recordset")
sql="select * from Admin where UN = '" & UserName & "'"
rs.open sql,conn,1,1

if rs.bof and rs.eof then
  rs.close
  conn.close
  set rs=nothing
  set conn=nothing
response.Write(sql) 
  response.Write(" <script>alert('No such Administrator!');history.go(-1); </script>") 
else
if not(password=rs("PW")) then
rs.close
  conn.close
  set rs=nothing
  set conn=nothing
  response.Write(" <script>alert('Your password is incorrect!');history.go(-1); </script>") 
else
rs.close
  conn.close
  set rs=nothing
  set conn=nothing
  response.Write(" <script>window.location.href('AdminManage.asp');</script>")
  end if
end if
%>
但是有点问题是,只有第一次可以正确验证。
我测试的时候故意打错密码,它第一次可以正确判断密码不正确。
之后就全部过不了
if rs.bof and rs.eof then
  rs.close
  conn.close
  set rs=nothing
  set conn=nothing
response.Write(sql) 
  response.Write(" <script>alert('No such Administrator!');history.go(-1); </script>") 
不管正确与否,都是“No such administrator!”
请问是access不正常推出的问题吗。

作者: johndu81   发布时间: 2011-09-18

将缓存清除后试一试

作者: yaxiya   发布时间: 2011-09-18

不要用 history.go(-1) ,它会缓存上次的数据。
用 Response.Redirect("此网页URL")

作者: theforever   发布时间: 2011-09-18

用response.clear吗?还是response.end.

作者: johndu81   发布时间: 2011-09-18

to theforever
改成:
<!--#Include file="../func/conn.asp"-->
<%

dim UserName,Password
UserName=trim(request("UserName"))
Password=trim(request("Password"))

if UserName="" then
response.Write(" <script>alert('Your username is blank!'); </script>") 
Response.Redirect("AdminLogin.asp")
end if
if Password="" then
response.Write(" <script>alert('Your password is blank!'); </script>") 
Response.Redirect("AdminLogin.asp")
end if

set rs=server.createobject("adodb.recordset")
sql="select * from Admin where UN = '" & UserName & "'"
rs.open sql,conn,1,1

if rs.bof and rs.eof then
  rs.close
  conn.close
  set rs=nothing
  set conn=nothing
  response.Write(" <script>alert('No such Administrator!'); </script>") 
Response.Redirect("AdminLogin.asp")
else
if not(password=rs("PW")) then
rs.close
  conn.close
  set rs=nothing
  set conn=nothing
  response.Write(" <script>alert('Your password is incorrect!'); </script>") 
Response.Redirect("AdminLogin.asp")
else
rs.close
  conn.close
  set rs=nothing
  set conn=nothing
Response.Redirect("AdminManage.asp")
  end if
end if

%>
它不会有提示,直接回到我的登录界面。

作者: johndu81   发布时间: 2011-09-18

ie->常规->internet临时文件:"设置"按钮->选中"每次访问此页时检查"

作者: yaxiya   发布时间: 2011-09-18