Using ASP to realize landing page control source code

Source: Internet
Author: User
Tags variables variable
Control | page | source code

We usually want to set up a user login system in the production site, that is, when users can see the corresponding content after landing, this method is often used, the specific implementation of the flowchart:

The specific ASP source code is as follows: (including 3 files)

  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" >
<title> Member Login System </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body>
If strfailed <> "" Then
Response.Write "<p>" & strfailed & "</p>" & VbCrLf
End If
%><form method= "POST" action= "Login.asp" >
<p>
<label for= "username" > Username:</label>>
<input type= "text" id= "username name=" username ">
</p>
<p>
<label for= "password" > Password:</label>
<input type= "password" id= "password" name= "password" >
</p>
<p>
<input type= "Submit" Name= "submitted" value= "Login" >
</p>
</form>
</body>

  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" >
<title>secret area</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body>
<p>
Welcome to the secret area.
</p>
</body>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.