1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

快来帮帮我,一个ASP问题

本帖由 leehui19832006-03-05 发布。版面名称:后端开发

  1. leehui1983

    leehui1983 New Member

    注册:
    2006-02-26
    帖子:
    130
    赞:
    0
    我想设计一个根据SESSION值不为空才允许进入页面的代码,可是现在变成随便输入用户名和密码就能进入,请教下啊是怎么回事?请帮我更正啊
    <!--#include file="conn.asp"-->
    <%
    dim admin,pwd,adminname,adminpwd
    set rs=server.createobject("ADODB.Recordset")
    sql="select * from admin where admin='" &admin& "'"
    rs.open sql,conn,1,1
    if rs.eof and rs.bof then
    response.write"<script>alert('用户名或密码不存在');history.back();</script>"
    else
    adminname=rs("admin")
    adminpwd=rs("pwd")
    rs.close
    set rs=nothing
    end if
    if admin<>adminname then
    response.write"<script>alert('用户名不存在');history.back();</script>"
    elseif pwd<>adminpwd then
    response.Write"<script>alert('密码错误');history.back();</script>"
    elseif request.form("name")="" then
    response.write"<script>alert('用户名不能为空');history.back();</script>"
    elseif request.Form("password")="" then
    response.write"<script>alert('密码不能为空');history.back();</script>"
    else
    session("admin")=replace(trim(request.Form("name")),"'","")
    session("pwd")=request.Form("password")
    response.Redirect("admin_edit.asp")
    end if
    %>
     
  2. 小叶

    小叶 New Member

    注册:
    2005-09-04
    帖子:
    17,941
    赞:
    33
    <!--#include file="conn.asp"-->
    <%
    dim admin,pwd,adminname,adminpwd
    set rs=server.createobject("ADODB.Recordset")
    sql="select * from admin where admin='" &admin& "'"
    rs.open sql,conn,1,1
    if rs.eof and rs.bof then
    response.write"<script>alert('用户名或密码不存在');history.back();</script>"
    else
    adminname=rs("admin")
    adminpwd=rs("pwd")
    rs.close
    set rs=nothing
    end if
    if admin<>adminname then
    response.write"<script>alert('用户名不存在');history.back();</script>"
    elseif pwd<>adminpwd then
    response.Write"<script>alert('密码错误');history.back();</script>"
    elseif request.form("name")="" then
    response.write"<script>alert('用户名不能为空');history.back();</script>"
    elseif request.Form("password")="" then
    response.write"<script>alert('密码不能为空');history.back();</script>"
    else
    response.Redirect("admin_edit.asp")
    end if
    %>

    自己检查一下这两行哦。。
     
  3. leehui1983

    leehui1983 New Member

    注册:
    2006-02-26
    帖子:
    130
    赞:
    0
    改成这样结果变成不能跳转页面了,还是请小叶告诉我错哪里吧
    session("admin")=adminname
    session("pwd")=adminpwd
     
  4. leehui1983

    leehui1983 New Member

    注册:
    2006-02-26
    帖子:
    130
    赞:
    0
    原来是修改的时候漏掉提取表单内容,现在这样应该没有错了
    <!--#include file="conn.asp"-->
    <%
    dim admin,pwd,adminname,adminpwd
    admin=request.form("name")
    pwd=request.Form("password")
    set rs=server.createobject("ADODB.Recordset")
    sql="select * from admin where admin='" &admin& "'"
    rs.open sql,conn,1,1
    if rs.eof and rs.bof then
    response.write"<script>alert('用户名或密码不存在');history.back();</script>"
    else
    adminname=rs("admin")
    adminpwd=rs("pwd")
    rs.close
    set rs=nothing
    end if
    if admin<>adminname then
    response.write"<script>alert('用户名不存在');history.back();</script>"
    elseif pwd<>adminpwd then
    response.Write"<script>alert('密码错误');history.back();</script>"
    elseif request.form("name")="" then
    response.write"<script>alert('用户名不能为空');history.back();</script>"
    elseif request.Form("password")="" then
    response.write"<script>alert('密码不能为空');history.back();</script>"
    else
    session("admin")=adminname
    session("pwd")=adminpwd
    response.Redirect("admin_edit.asp")
    end if
    %>