asp判断是否登录的代码

TAG: 时间:2012-12-26 00:00:00

   

    <%
    dim admin_username,admin_password
    admin_username=trim(request("username"))
    admin_password=trim(request("password"))
    if admin_username="" or admin_password="" then
    response.write "<script>alert(’对不起,用户名和密码不能为空!’);document.location.href=’index.asp’;</script>"
    response.end
    end if’这里是判断输入是不是为空
    %>
    <%
    set conn = Server.CreateObject("ADODB.Connection")
    DBPath = Server.MapPath("db1.mdb")
    conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
    Set rs = Server.CreateObject("ADODB.Recordset")
    sql="select * from info where Username=’"&admin_username&"’" 
    rs.open sql,conn,1,1
    if not rs.eof then
    ’这个IF判断的意思是:输入的用户名和数据库里的用户名一致的时候。这是你还要判断输入的密码对不对,是吧?所以就有下面的IF。
    if rs("UserPwd")<>admin_password then
    response.write "<script>alert(’对不起,密码不正确,请重新输入’);document.location.href=’index.asp’;</script>"
    response.end
    else 
    response.redirect "index2.asp"
    ’密码也对的情况下,就可以登录index2.asp页面了 
    ’一般,你最好是还要设置session。这样方便别的页面判断是不是登录了。如
    ’session("jsusername")=username 
    ’session("jsPassword")=Password 
    end if 
    end if 
    %>  
    <%  
    rs.close 
    set rs=nothing
    conn.close 
    set rs=nothing
    %>

北京网站建设 北京网页设计 网站制作(www.bjycxf.com



分享到:
YC & 原创官方微信
Contact Us & 联系我们

TEL: 010-68703788/66/87/89

地址:北京市海淀区大钟寺十三号院华杰大厦11B8室

© Copyright 2004-2014 bjycxf.com All Rights Reserved 版权所有

京ICP备09080439号 京公网安备11010802012755号