set conn= Server.CreateObject("adodb.connection")
conn.open "Provider=Microsoft.jet.oledb.4.0data source=" &server.MapPath("_ringDB.mdb")
这条语句写到conn.asp中,然后在任何网页中插入
<!--#include file=conn.asp-->就可以了,以后也不用写了.
接收网页传递,你要明白,一般输入用户名和密码是一个界面,检查用户名密码是另一个界面.你必须接收传递过来的用户名和密码,也就是上一个网页的form组件.当点"提交"后,传递到这个检查页面中.
在这个界面接收username 和 password .
("")中的username是上一个网页中textbox中的值,也就是用户输入的值,密码也一样.在检查页面中,接收传来的值.代码如下:
username=request.querystring("username")
password=request.querystring("password")
你用recordset对像建立rs
你SQL语句有问题.不用那么麻烦,我写的就可以:
set rs=server.createobject("adodb.recordset")
sql="select * from byuser where _username='"&username&"' and _password='"&password&"'"
rs.open sql,conn,1,3
判断代码:
if rs.eof then
response.write"输入的用户和密码错误!"
response.end
else
session("admin")=rs("_username")
response.Redirect("showbook.asp?username="&username&"&pageno="&pageno&"")
----------------------------------------
我解释一下判断,当rs指针到数据库底,证明没有找到username和password相同的数据,所以,该用户没有注册,或者用户名或密码错误导致,提示"输入的用户和密码错误!"
否则,证明rs指针没有到底,已经找到相同的值.建立session,为了让用户有特殊 *** 作,比如说,是否允许修改或删除,
只要判断session的值是否为空就可以了
session("admin")=rs("_username")
session("admin")的值就是rs("_username")的值,比如它的值是"小王"
判断是否有权限,当在其他的网页当中:
if session("admin")=rs("_username")
........
else
respose.write("你没有登陆,无权 *** 作!")
endif
------------------------------------
只有通过你对session("admin")=rs("_username")的赋值
上面的验证才能通过.
明白了么?
累死我了,你太栗色,1分也不给,别人懂的都不原因回答你的问题.
你要知道我费了大半天的功夫.
分类: 教育/科学 >>学习帮助问题描述:
希望大家多多帮忙!!!!!!
解析:
1,(index 用户登陆页面)
<!-- #include file="conn" -->
<!-- blog.soowooo 悠悠长假期 -->
<>
<head>
<meta -equiv="Content-Type" content="text/charset=gb2312">
<title>会员</title>
<style type=text/css>
<!--
body,td,th {
font-family: 宋体
font-size: 14px
}
-->
</style>
</head>
<body>
<center>
<p>会员注册系统</p>
<form name=form1 method="post" action="login">
<table width=34% border=0>
<tr>
<td width=33% height=30>用户名:</td>
<td width=67% height=30><input name=username type=text id="username" size="15"></td>
</tr>
<tr>
<td height=30>密 码:</td>
<td height=30><input name=password type=password id="password" size="15"></td>
</tr>
<tr>
<td colspan="2" align=center><input type=submit name=Submit value="确定">
<input type=reset name=Submit value="重置"></td>
</tr>
<tr>
<td colspan="2"><a href="reg" target="_self">注册</a></td>
</tr>
</table>
</form>
</center>
</body>
</>
2,(login 用户数据处理文件)
<!-- #include file="conn" -->
<%
'打开数据库判断用户是否存在,info为表名,username为字段名
set rsc=server.createobject("adodb.recordset")
sqlc="select * from info where username='"&request.Form("username")&"' and password='"&request.Form("password")&"'"
rsc.open sqlc,conn,1,1
session("username")=rsc("username")
session("password")=rsc("password")
session.Timeout=30
set rsc=nothing
response.Redirect("change")
'如果用户不存在,session("username")为空
%>
3,(change 用户信息修改页面)
<!-- #include file="conn" -->
<>
<head>
<meta -equiv="Content-Type" content="text/charset=gb2312">
<title>修改</title>
<style type=text/css>
<!--
body,td,th {
font-size: 14px
}
-->
</style></head>
<center>
<body>
<br>
<%
set rsc=server.createobject("adodb.recordset")
sqlc="select * from info where username='"&session("username")&"' and password='"&session("password")&"'"
rsc.open sqlc,conn,1,1
nr=rsc("password")
username=rsc("username")
password=rsc("password")
sex=rsc("sex")
qq=rsc("qq")
mail=rsc("mail")
add=rsc("add")
personalinfo=rsc("personalinfo")
vv=rsc("ntime")
set rsc=nothing
if nr="" then
response.Redirect("index")
end if
if strp(nr,request.Form("password"))=0 then
response.Write("欢迎你!"&request.Form("username"))
response.Write("你是在"&vv&"注册的")
session("username")=request.Form("username")
end if
if session("username")="" then
response.Redirect("index")
end if
%>
<form name=form1 method="post" action="change?ac=ch">
<table width=39% height=105 border=0 >
<tr>
<td width=27% height=30>用户名:</td>
<td width=73% height=30><input name=username type=text id="username" value="<%=username%>">
*</td>
</tr>
<tr>
<td height=30>密 码:</td>
<td height=30><input name=password type=text id="password" value="<%=password%>">
*</td>
</tr>
<tr>
<td height=30>性 别:</td>
<td height=30><input name=sex type=text id="sex" value="<%=sex%>"></td>
</tr>
<tr>
<td height=30>QQ:</td>
<td height=30><input name=qq type=text id="qq" value="<%=qq%>"></td>
</tr>
<tr>
<td height=30>Mail:</td>
<td height=30><input name=mail type=text id="mail" value="<%=mail%>"></td>
</tr>
<tr>
<td height=30>地 址:</td>
<td height=30><input name=add type=text id="add" value="<%=add%>"></td>
</tr>
<tr>
<td>介绍</td>
<td><textarea name=personalinfo cols="30" rows="6" id="personalinfo"><%=personalinfo%></textarea></td>
</tr>
<tr>
<td></td>
<td><input type=submit name=Submit value="修改">
<a href="change?se=y" target="_self">退出系统</a></td>
<% if strp(request.QueryString("se"),"y")=0 then
session("username")=""
response.Redirect("index")
end if
%>
</tr>
</table>
</form>
<%
if strp(request.QueryString("ac"),"ch")=0 then
set rs=server.createobject("adodb.recordset")
sql="select * from info where username='"&session("username")&"'"
rs.open sql,conn,1,3
rs("username")=request.Form("username")
rs("password")=request.Form("password")
rs("mail")=request.Form("mail")
rs("sex")=request.Form("sex")
rs("qq")=request.Form("qq")
rs("add")=request.Form("add")
rs("personalinfo")=request.Form("personalinfo")
rs.update
set rs=nothing
response.Write("修改完成!")
end if
%>
</body>
</center>
</>
4,(reg 新用户注册页面)
<>
<head>
<meta -equiv="Content-Type" content="text/charset=gb2312">
<title>用户注册</title>
<style type=text/css>
<!--
body,td,th {
font-family: 宋体
font-size: 14px
}
-->
</style>
</head>
<body>
<center>
用户注册<br>
<%
=request.QueryString("msg")
%>
<form name=form1 method="post" action="addnewdata?ac=adduser">
<table width=39% height=105 border=0 >
<tr>
<td width=27% height=30>用户名:</td>
<td width=73% height=30><input name=username type=text id="username">
*</td>
</tr>
<tr>
<td height=30>密码:</td>
<td height=30><input name=password type=password id="password">
*</td>
</tr>
<tr>
<td height=30>确定密码:</td>
<td height=30><input name=password2 type=password id="password2">
*</td>
</tr>
<tr>
<td height=30>性别:</td>
<td height=30><input name=sex type=text id="sex"></td>
</tr>
<tr>
<td height=30>QQ:</td>
<td height=30><input name=qq type=text id="qq"></td>
</tr>
<tr>
<td height=30>Mail:</td>
<td height=30><input name=mail type=text id="mail"></td>
</tr>
<tr>
<td height=30>地址:</td>
<td height=30><input name=add type=text id="add"></td>
</tr>
<tr>
<td>个人介绍</td>
<td><textarea name=personalinfo cols="30" rows="6" id="personalinfo"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type=submit name=Submit value="提交"></td>
</tr>
</table>
</form>
</center>
</body>
</>
5,(addnewdata 新用户注册数据处理文件)
<!-- #include file="conn" -->
<>
<head>
<meta -equiv="Content-Type" content="text/charset=gb2312">
<title>成功</title>
</head>
<body>
<%
ac=request.QueryString("ac")
msg="注册错误信息"
if request.Form("username")="" then
msg=msg&"<br>"&"用户名不能为空"
end if
if strp(cstr(request.Form("password")),cstr(request.Form("password2")))<>0 then
msg=msg&"<br>"&"两次密码输入不同"
end if
if len(request.Form("password"))<6 then
msg=msg&"<br>"&"密码太简单"
end if
if strp(msg,"注册错误信息")>0 then
response.Redirect("reg?msg="&msg)
end if
if ac="adduser" then
set rsc=server.createobject("adodb.recordset")
sql="select * from info where username='"&request.Form("username")&"'"
rsc.open sql,conn,1,1
ck=rsc("username")
set rsc=nothing
if ck<>"" then
msg=msg&"<br>"&"用户名被人注册"
response.Redirect("reg?msg="&msg)
end if
dsql="select * from info where id is null"
set rs=server.createobject("adodb.recordset")
rs.open dsql,conn,1,3
rs.addnew
rs("username")=request.Form("username")
rs("password")=request.Form("password")
rs("mail")=request.Form("mail")
rs("sex")=request.Form("sex")
rs("qq")=request.Form("qq")
rs("add")=request.Form("add")
rs("personalinfo")=request.Form("personalinfo")
rs("ntime")=now
rs.update
set rs=nothing
%>
<center>
<a href="index" target="_self">注册成功,点击登陆</a>
</center>
<%
end if
%>
</body>
</>
6,(conn 数据库连接文件)
<%
'连接数据库开始
dim conn,rs,sql
on error resume next
dbpath=server.mappath("userinfo.mdb")
set conn=server.createobject("adodb.connection")
conn.open "PROVIDER=Microsoft.jet.OLEDB.4.0data source="&dbpath
'创建记录对象
set rs=server.createobject("adodb.recordset")
%>
7,(userinfo.mdb ACCESS 数据库)
在ACCESS中建一个表,然后在这个表中建立字段名称
表名:info
字段名称 数据类型
id 自动编号
username 文本
password 文本
sex 文本
quest 文本
qq 文本
mail 文本
personalinfo 文本
ntime 文本
注册<!-- #include file="conn.asp" -->
<%
username=request.Form("name")
pass=request.Form("pass")
if username="" or pass="" or pass1="" then
response.Redirect "zhuce.asp"
else
if pass <>pass1 then
response.redirect"zhuce.asp"
else
set rs=server.createobject("adodb.recordset")
sql="select * from admin "
rs.open sql,conn,3,3
rs.addnew
rs("name")=username
rs("pass")=pass
rs.update
end if
end if
%>
等入
<!--#include file="conn.asp" -->
<%
if request.QueryString("action")="login" then
if cstr(Session("GetCode"))<>cstr(Request.Form("VerifyCode")) then
Response.Write("<script>alert(""您输入的确认码和系统产生的不一致,请重新输入。返回后请刷新登录页面后重新输入正确的信息。"")location.href=""Login.asp""</script>")
Response.End
end if
if request.form("name")="" then
Response.Write("<script language=""JavaScript"">alert(""用户名不能为空!"")history.go(-1)</script>")
response.End()
end if
if request.form("pass")="" then
Response.Write("<script language=""JavaScript"">alert(""请输入正确的密码!"")history.go(-1)</script>")
response.End()
end if
set rs=server.createobject("adodb.recordset")
rs.open "select * from admin where name='" &request.Form("name") &"' AND pass='" &md5(Request.Form("pass")) &"'",conn,3,3
if not rs.eof then
if request.Form("name")=rs("name") and md5(Request.Form("pass"))=rs("pass") then
Response.Write("<a href='list.asp?key="&rs("name")&"'>点击返回首页</a>")
else
Session("GetCode")=""
rs.close:set rs=nothing
Response.Write("<script language=""JavaScript"">alert(""用户不存在!"")history.go(-1)</script>")
response.end
end if
else
Session("GetCode")=""
rs.close:set rs=nothing
Response.Write("<script language=""JavaScript"">alert(""请输入正确的密码!"")history.go(-1)</script>")
response.End()
end if
end if
%>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)