国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

ASP 連接Access數據庫的登陸系統

發(fā)布時(shí)間:2021-08-17 12:10 來(lái)源: 閱讀:0 作者:yongh701 欄目: ASP 歡迎投稿:712375056

一、基本目標

首先在A(yíng)ccess數據Database.mdb中存在著(zhù)用戶(hù)信息表test:


編寫(xiě)一個(gè)登陸系統,如果用戶(hù)輸入的用戶(hù)名在表中沒(méi)有,則提示“查無(wú)此人”,如果輸入密碼錯誤,則提示“密碼錯誤”


如果用戶(hù)輸入的用戶(hù)名與密碼都正確,則跳轉到登陸成功頁(yè)


登陸成功頁(yè)在普通情況下,不允許通過(guò)輸入網(wǎng)址就能訪(fǎng)問(wèn)


二、基本思想

使用asp的session對象確保了用戶(hù)名與密碼的傳遞。

彈出部分使用了javascript的腳本語(yǔ)言,使用asp對用戶(hù)信息表進(jìn)行查詢(xún)。

站點(diǎn)的基本結構如下:


三、制作過(guò)程
整個(gè)站點(diǎn)使用utf-8碼保證不會(huì )亂碼,所以每一頁(yè)在頁(yè)頭必須有<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />,如果使用DW的高版本則自動(dòng)添加,低版本請把gb2312改成utf-8,記事本自便。 

1、登陸頁(yè)面login.html僅僅是一個(gè)表單的靜態(tài)頁(yè)面。關(guān)鍵是用post方法傳遞信息,Action是到login.asp

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>login</title>
</head>

<body>
<form method="post" action="login.asp"> 
username:<input type="text" name="username" />
password:<input type="password" name="password" />
<input type="submit" value="login" />
</form>
</body>
</html>

 2、login.asp登陸驗證頁(yè)面是本系統最核心的頁(yè)面

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>login</title>
</head>

<body>

<%
'向把login.html傳過(guò)來(lái)的兩個(gè)信息用變量保存起來(lái)
username=Request.Form("username")
password=Request.Form("password")
'數據庫是上一級目錄的Database.mdb
%>
<%
db="../Database.mdb"
'連接數據庫指定動(dòng)作,這段必須獨立地占用一個(gè)<%%>否則在某些情況下IE8會(huì )出錯
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft Access Driver (*.mdb)};pwd=admin;dbq=" & Server.MapPath(db) 
%>
<%
Set rs = Server.CreateObject( "ADODB.Recordset" )
'看表中是否有此username
sql = "select * from test where username='"+username+"';"
rs.open sql,conn,1,3
'如果什么都查不到,彈窗,彈回login.html
if (rs.bof and rs.eof) then
%>
<script>
alert("查無(wú)此人");
window.location.href = "login.html";
</script>
<%
'否則拿查出來(lái)的密碼,與用戶(hù)輸入的密碼作對比,看是否一致
'查出來(lái)的密碼必須先用一個(gè)變量接住,在A(yíng)SP中不能直接比較
else
dbpwd=rs("password")
'如果不一致,則彈窗,ASP沒(méi)有!=,表示不等于請用<>
if password<>dbpwd then
%>
<script>
alert("密碼錯誤");
window.location.href = "login.html";
</script>
<%
else
'如果用戶(hù)名密碼都輸入正確,則有此用戶(hù),timeout是為了防止用戶(hù)非正常退出的,如果5分鐘沒(méi)有任何操作則判定其已經(jīng)退出,ok是正常登陸的標志
Session.Timeout=5
Session("username")=username
Session("login")="ok"
%>
<script>
alert("登陸成功");
window.location.href = "success.asp";
</script>
<%
end if
end if
'用完數據庫記得關(guān)
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
</body>
</html>

 3、success.asp
 沒(méi)什么好說(shuō)的,關(guān)鍵是看他是否有正常登陸標志,login的內容是否為ok,沒(méi)有則將其彈出登陸頁(yè)面 

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>歡迎登陸</title>
</head>

<body>
<%
if Session.Contents("login")<>"ok" then 
%>
<script>
alert("請正常登陸!");
window.location.href = "login.html";
</script>
<%
else
Response.Write("歡迎登陸,"+Session.Contents("username"))
end if
%>
<a href="exit.asp">正常退出</a>
</body>
</html>

4、exit.asp退出處理頁(yè)面 

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>正在退出...</title>
</head>

<body>
<%
'所有session立即超時(shí),并且移除所有session
Session.Abandon
Session.Contents.RemoveAll()
%>
<script>
window.location.href = "login.html";
</script>
</body>
</html>

以上就是本文的全部?jì)热?,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。

久久久久久久久久久大尺度免费视频| 国产线播放免费人成视频播放| 日韩中文字幕V亚洲中文字幕| 国产精品亚洲精品日韩已满| 亚洲AV无码国产精品色午友在线| 久久不见久久见中文字幕免费|