asp制作登录网页(asp制作登录界面)
制作ASP简单登陆和处理页面
!--#include file="md5.asp"-- !--有md5加密则加上 无则删除--
%
data_url="data/db.mdb"'数据库路径 修改此处
data_table="admin"'数据表名
admin_zd="adminname"'用户名字段名
pssword_zd="pssword"'密码字段名
request_name="username"'表单中用户名文本域名称
request_password="password"'表单中密码文本域名称
'连接数据库
connstr="DBQ="+server.mappath(data_url)+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
Set conn=Server.CreateObject("ADODB.CONNECTION")
conn.open connstr
admin=request(request_name)
password=request(request_password)
password=md5(password)'如果你的密码经过asp加密保留 否者删除此行
set rs=server.CreateObject("adodb.recordset")
sql="select * from ["data_table"] where "admin_zd"='" admin "' and "pssword_zd"='" password "'"
rs.open sql,conn,1,1
if not(rs.bof and rs.eof) then
session(admin_zd)=rs(admin_zd)
response.write"script language='javascript'location.href='admin_index.asp';/script"
else
response.write"script language='javascript'alert('登录失败!');location.href='index.asp';/script"
end if
rs.close
set rs=nothing
conn.close
set conn=nothing
%
你直接在我给你写的提示上修改相应的名称就行了
不行的话hi我
我给你详细说
要加分哦
有的话
用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("scriptlocation.href('index.asp')/script" )
else
response.write ("scriptalert('用户密码错误');location.href('denglu.asp')/script")
end if
end if
if rs.eof then
response.write ("scriptalert('用户帐号错误');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" ""
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
tdinput name="us" type="text" id="us"/td
/tr
tr
td密码:/td
tdinput name="pa" type="password" id="pa" value=""/td
/tr
tr
td?/td
tdinput 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
%
asp程序实现简单的注册,登录网页的源代码
1,(index.asp 用户登陆页面)
!-- #include file="conn.asp" --
!-- blog.soowooo.cn 悠悠长假期 --
html
head
meta http-equiv="Content-Type" content="text/html; 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.asp"
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.asp" target="_self"注册/a/td
/tr
/table
/form
/center
/body
/html
2,(login.asp 用户数据处理文件)
!-- #include file="conn.asp" --
%
'打开数据库判断用户是否存在,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.asp")
'如果用户不存在,session("username")为空
%
3,(change.asp 用户信息修改页面)
!-- #include file="conn.asp" --
html
head
meta http-equiv="Content-Type" content="text/html; 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.asp")
end if
if strcomp(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.asp")
end if
%
form name="form1" method="post" action="change.asp?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
tdtextarea name="personalinfo" cols="30" rows="6" id="personalinfo"%=personalinfo%/textarea/td
/tr
tr
td /td
tdinput type="submit" name="Submit" value="修改"
a href="change.asp?se=y" target="_self"退出系统/a/td
% if strcomp(request.QueryString("se"),"y")=0 then
session("username")=""
response.Redirect("index.asp")
end if
%
/tr
/table
/form
%
if strcomp(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
/html
4,(reg.asp 新用户注册页面)
html
head
meta http-equiv="Content-Type" content="text/html; 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.asp?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
tdtextarea name="personalinfo" cols="30" rows="6" id="personalinfo"/textarea/td
/tr
tr
td /td
tdinput type="submit" name="Submit" value="提交"/td
/tr
/table
/form
/center
/body
/html
5,(addnewdata.asp 新用户注册数据处理文件)
!-- #include file="conn.asp" --
html
head
meta http-equiv="Content-Type" content="text/html; charset=gb2312"
title成功/title
/head
body
%
ac=request.QueryString("ac")
msg="注册错误信息"
if request.Form("username")="" then
msg=msg"br""用户名不能为空"
end if
if strcomp(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 strcomp(msg,"注册错误信息")0 then
response.Redirect("reg.asp?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.asp?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.asp" target="_self"注册成功,点击登陆/a
/center
%
end if
%
/body
/html
6,(conn.asp 数据库连接文件)
%
'连接数据库开始
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.0;data source="
'创建记录对象
set rs=server.createobject("adodb.recordset")
%
7,(userinfo.mdb ACCESS 数据库)
在ACCESS中建一个表,然后在这个表中建立字段名称
表名:info
字段名称 数据类型
id 自动编号
username 文本
password 文本
sex 文本
quest 文本
qq 文本
mail 文本
personalinfo 文本
ntime 文本
怎样设计一个asp登陆网页,完成以下步骤?
1、登录页面接收表单传来的值,然后把接收来的用户名和密码逐一和你数据库里的进行对比,如果正确就写COOKIES值并进到要登录的页面里去。如果没有该用户或者密码不正确则不要登录,直接转到登录页面。