武汉到苏梅岛攻略:用asp编写程序啊……考试要用的,很急,谢谢啦……

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 07:18:30
在login.htm文件中包含一段表单,主要功能将用户填空的用户名和密码提交给服务器,让服务器上的verify.asp页面验证用户名和密码?(用asp编写)
一定需要连接到数据库的吗?信息会否就是存放在verify.asp中,然后把用户名和密码递交到这个页面上进行验证呢?如果是这样的话,又怎样验证呢?

<!--#include file="../conn.asp" -->
<%
if Request.Form("usr")<>"" then
call cklogin()
end if

sub cklogin()
REM ------获取用户名和密码------

dim iusr
dim ipsd
iusr=Request.Form("usr")
ipsd=Request.Form("psd")

REM ------检测用户名和密码是否合法------

set rs=server.createobject("adodb.recordset")
sql="select * from comicet_config where adminusr='"&iusr&"' and adminpsd='"&ipsd&"'"
rs.open sql,conn,1,1
if rs.bof and rs.eof then
rs.close
Set rs=Nothing
conn.close
Set conn=Nothing
Response.Redirect"error.asp?erro=身份确认失败"
elseif ipsd<>rs("adminpsd") then
rs.close
Set rs=Nothing
conn.close
Set conn=Nothing
Response.Redirect"error.asp?erro=身份确认失败"
end if

REM ------如果用户合法则存储用户数据在Cookies------

session("admin")="on"
rs.close
set rs=nothing
conn.close
set conn=nothing
Response.Redirect "index.asp"
end sub
conn.close
Set conn=Nothing
%>
<html>
<head>
<title>用户登陆</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../index.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="5" topmargin="10">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
<tr>
<td>
<table width="300" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td bgcolor="#cccccc" height="3"></td>
</tr>
<tr>
<td bgcolor="#f7f7f7">
<table width="300" border="0" cellspacing="0" cellpadding="5" align="center">
<form name="form1" method="post" action="login.asp">
<tr>
<td colspan="2" align="center">用户登陆</td>
</tr>
<tr>
<td width="60">用户名:</td>
<td width="220">
<input type="text" name="usr" class="input">
<input type="image" name="Submit" src="../images/ok.gif">
</td>
</tr>
<tr>
<td width="60">密码:</td>
<td width="220">
<input type="password" name="psd" class="input">
</td>
</tr>
</form>
</table>
</td>
</tr>
<tr>
<td bgcolor="#cccccc" height="3"></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
====================================================================
<!--#include file="../conn.asp" -->

这个是创建数据库连接对象的,代码是
<%
db="../mdb/XXX.mdb" '写你的数据库名字
Set conn = Server.CreateObject("ADODB.Connection")
MyConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
Conn.Open MyConn
%>
可以单独写成.asp,也可以直接写在代码里面,如果很多页面都要访问,还是单独写然后用include,比较方便,出了错也不用一个一个改

这个页面是把表单的提交和数据验证放在一起的,如果要分开的话asp代码部分和html代码部分分别提出来,然后把
<form name="form1" method="post" action="login.asp">
改成您要的那个verfiy.asp就可以了。
如果不规定跳转页面的话redirect那个可以随便写