用ASP实现登陆页面控制的源代码
2008-02-23 09:32:04来源:互联网 阅读 ()
我们在制作网站时通常想设置用户登陆系统,也就是说当用户登陆之后可以看到相应的内容,这种方法被经常使用了,具体的实现的流程图:
具体ASP源代码如下:(包括3个文件)
login.asp
<%@ Language="vbscript" %>
<% Option Explicit %>
<% Response.Buffer = True %>
<!--#include file="dbConn.asp"-->
<%
'================================================
' Was the form submitted?
' If so, lets check the Username and Password
'================================================
If Request.Form("Submitted") = "login" Then
' Declare our variables
Dim objConn, objRS, strSQL
' Create Connection Object
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strConnect
' Build SQL String
strSQL = "SELECT * FROM MemberInfo WHERE Username='" & Request.Form("Username") & "'"
' Create Recordset Object
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn
If objRS.EOF Then
'================================================
' Does the Username exist?
' If not, set strFailed and destroy all objects.
' We'll then display the login form again.
'================================================
strFailed = "Invalid Username"
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
Else
'================================================
' Username exists - is the password correct?
' If not, set strFailed and destroy all objects.
' We'll then display the login form again.
'================================================
If objRS.Fields("Password") <> Request.Form("Password") Then
strFailed = "Invalid Password"
objRs.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
Else
'================================================
' Username and password are valid.
' Set session variable.
' Destroy all objects.
' Redirect to secret page
'================================================
Session("ValidUser") = "true"
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
Response.Redirect "secret-page.asp"
End If
End If
End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>会员登陆系统</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<h1>Login Area</h1><%
If strFailed <> "" Then
Response.Write "<p>" & strFailed & "</p>" & vbCrLf
End If
%><form method="post" action="login.asp">
<p>
<label for="username">用户名:</label>>
<input type="text" id="username name="username">
</p>
<p>
<label for="password">密码:</label>
<input type="password" id="password" name="password">
</p>
<p>
<input type="submit" name="Submitted" value="login">
</p>
</form>
</body>
</html>
dbConn.asp
<%
' Declare our variables
Dim strDBVirtualPath, strDBLocation, strConnect
strDBVirtualPath = "memberDB/LoginInfo.mdb"
strDBLocation = Server.MapPath(strDBVirtualPath)
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBLocation
Response.Write Chr(13)
%>
secret-page.asp
<%@ Language="vbscript" %>
<% Option Explicit %>
<% Response.Buffer = True %>
<%
'=====================================
' Is the Session variable "ValidUser"
' set to "true"? - If not, redirect to
' login.asp
'=====================================
If Session("ValidUser") <> "true" Then
Response.Redirect "login.asp"
End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Secret Area</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<h1>Secret Area</h1>
<p>
Welcome to this secret area.
</p>
</body>
</html>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:用ASP产生随即密码的程序
下一篇:菜鸟学习ASP教程之编程基础
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash