posts - 0,  comments - 1,  trackbacks - 0
用ASP制作网站登录系统 环境:DW+ASP+ACCESS+IIS 作者:lanier(http://x8.Maicoo.com-麦客学吧)

一、数据库的建立

打开ACCESS2000,新建数据库(lanier_db.mdb),表名:login

Login表包函的字段:Id;userid(用户名);pwd(密码)

二、打开Dreamweaver MX 新建conn.asp页面.然后把下面的代码复制到conn.asp里。


<%dim connset conn=Server.createobject("adodb.connection")conn.open "provider=microsoft.jet.oledb.4.0;data source="&server.mappath("lanier_db.mdb")
If err.number<>0 then
Response.write(
"连接数据库时产生错误!")Response.End
End if%>

用到此页面时包括即可:<!--#include file="conn.asp"-->

三、新建Login.asp页

……
<form method="post" action="check.asp">
用户名:
<input type="text" name="userid" size="20">
密  码: 
<input type="text" name="pwd" size="20">
<input type="submit" name="submit1" value="登录">
<input type="reset" name="button1" value="清除">
</form>
……

将此页的用户名及密码提交到check.asp进行校验.

四、建立check.asp页

<!--#include file="conn.asp"-->
<%
Dim Rs,Sql,Userid,Pwd
Userid
=Request.form("Userid"'提取login.asp页面的用户名;
Pwd=Request.form("pwd"'提取login.asp页面的密码;
Set Rs=Server.Createobject("adodb.recordset")
Sql
="select * from login where userid='"&Userid&""
Rs.open sql,conn,
1,1 
If rs.eof and rs.eof then  '判断用户名是否存在
Response.write "<script language=javascript>alert('用户不存在');history.go(-1);</script>"
Response.End
Elseif Rs("pwd")<>pwd then '判断密码是否正确
Response.write "<script language=javascript>alert('密码错误');history.go(-1);</script>"
Response.End
Else
Session(
"userid")=userid '把用户名写入session
Response.redirect("index.asp")
End if
%
>

把用户名写入Session("userid")是为了防上非法登录,只要在受限页面的头部加入下面代码:

<%
if session("userid")="" then
response.write(
"<script language=javascript>alert('对不起,你没有查看该页的权限或已超时,请重新登录!');location.href='loging.asp'</script>")
End
%
>
posted on 2007-07-06 10:30 李源 阅读(541) 评论(1)  编辑 收藏 引用 所属分类: 网络编程

FeedBack:
# re: 用ASP制作简单的网站登录系统
2009-02-12 15:11 | newpanda110
不错.学习  回复  更多评论
  
只有注册用户登录后才能发表评论。
<2009年2月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
1234567

常用链接

留言簿

文章分类

搜索

  •  

最新评论