手机站
网通分站
电信主站
密 码:
用户名:
热门关键字:  虚拟主机  cn域名  域名注册  非法  seo
当前位置 : 主页>网络编程>Asp编程>列表

用ASP实现登陆页面控制的源代码

来源:互联网 作者:west263.com 时间:2008-02-23 点击:
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

  我们在制作网站时通常想设置用户登陆系统,也就是说当用户登陆之后可以看到相应的内容,这种方法被经常使用了,具体的实现的流程图:

  具体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>

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名
注册