关于asp用户登录代码

一、

1.connection.asp里的代码是:
<%
set conn=server.createobject("adodb.connection")
conn.open "provider=microsoft.jet.oledb.4.0;data source="&server.MapPath("student.mdb")
%>

2.yanzheng.asp
里的代码是
:

<!--#include file="connection.asp"-->


<%
dim zhanghao,mima
zhanghao=request("zhanghao")
mima=request("mima")
if zhanghao="" then
%>
<script language=javascript>
alert("
帐号为空
");
location.href="denglu.asp"
</script>
<% end if %>
<% if mima="" then
%>
<script language=javascript>
alert("
密码为空
");
location.href="denglu.asp"
</script>
<% end if %>
<%set rs=server.createobject("adodb.recordset")
rs.open "select * from student where zhanghao='"&zhanghao&"'",conn,1,3
if not rs.eof then
if mima=rs("mima") then
session("zhanghao")=zhanghao
Response.write("<script>location.href('index.asp')</script>" )
else
response.write ("<script>alert('
用户密码错误
');location.href('denglu.asp')</script>")
end if
end if
if rs.eof then
response.write ("<script>alert('
用户帐号错误
');location.href('denglu.asp')</script>")
end if
set rs=nothing
rs.close

%>
二、

conn.asp   
   ------------------   
   <%   
   Set    conn=Server.CreateObject("ADODB.Connection")     
   connstr="DBQ="+server.mappath("haha.mdb")+";DefaultDir=;DRIVER={Microsoft    Access    Driver    (*.mdb)}"     
   conn.Open    connstr     
   %>   
   --------------------   
    
   index.asp   
   --------------------   
   <%@LANGUAGE="VBSCRIPT"    CODEPAGE="936"%>   
   <!DOCTYPE    HTML    PUBLIC    "-//W3C//DTD    HTML    4.01    Transitional//EN"    "http://www.w3.org/TR/html4/loose.dtd">   
   <html>   
   <head>   
   <meta    http-equiv="Content-Type"    content="text/html;    charset=gb2312">   
   <title>无标题文档</title>   
   </head>   
    
   <body>   
   <form    name="form1"    method="post"    action="login.asp">   
       <table    width="50%"    height="108"      border="0"    cellpadding="0"    cellspacing="0">   
           <tr>   
               <td>用户名:</td>   
               <td><input    name="us"    type="text"    id="us"></td>   
           </tr>   
           <tr>   
               <td>密码:</td>   
               <td><input    name="pa"    type="password"    id="pa"    value=""></td>   
           </tr>   
           <tr>   
               <td>&nbsp;</td>   
               <td><input    type="submit"    name="Submit"    value="提交"></td>   
           </tr>   
       </table>   
   </form>   
   </body>   
   </html>   
   ----------------------   
    
   login.asp   
   ----------------------   
   <!--#include    file="conn.asp"-->   
   <%   
   us=replace(request.form("us"),"'","")   
   pa=replace(request.form("pa"),"'","")   
   %>   
   <%   
   set    rs=server.createobject("adodb.recordset")   
   sql="select    *    from    haha    where    us='"&us&"'    and    pa='"&pa&"'"   
   rs.open    sql,conn,1,1   
   %>   
   <%   
   if    rs.eof    or    rs.bof    then   
   response.write"密码错误~"   
   else   
   response.redirect"main.asp"   
   end    if   
   %>   
   -------------------------

三、

连接数据库(conn.asp)   
   <%     
   dim    db,conn,connstr   
   db="@data.mdb"   
   set    Conn    =    server.CreateObject("ADODB.Connection")   
   connstr="provider=microsoft.jet.oledb.4.0;data    source="&    server.MapPath("../data/"&db&"")   
   conn.Open    connstr   
   %>   
   登录页面(login.asp   
   <%    @language=vbscript    %>   
   <!--#include    file="conn.asp"-->   
   <%     
   On    Error    Resume    Next   
   dim    uid   
   dim    pwd   
   uid=trim(request.Form("uid"))      '获得用户名   
   pwd=trim(request.form("pwd"))      '获得密码   
   dim    rs   
   set    rs=server.createobject("adodb.recordset")   
    
   if    uid<>""    then   
   dim    sqlstr   
   sqlstr="select    uid,pwd    from    admin    where    uid='"&replace(uid,"'","''")&"'    and    pwd='"&replace(pwd,"'","''")&"'"     
   rs.open    sqlstr,conn,3,1   
   if    not    rs.eof    then   
   session("uid")=uid   
   response.redirect    "login_ok.asp"      '重定位url   
   else   
   response.redirect    "error.htm"   
   end    if   
   else   
   response.redirect    "error.htm"   
   end    if   
   %>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值