ASP to prevent simultaneous landing problems

Source: Internet
Author: User
Tags add object copy current time end include key sql

There are two ways to implement this functionality:

1. Application

Using the Application object: If you are doing a large community, you may want to generate a appliaction for each login ID, which is not recommended here, although the program is simpler to design but has too many landing users and consumes server resources. Because the Appliaction object is easy to generate when the user logs on, but to be truly released as the user exits the system, there is no better way to go.

The following are the referenced contents:

<%
..... Take user name username .....
If Application (username) <> "" Then
Response.Write "This user is logged in"
Response.End
End If
Application (username) =username ' The user name of the user
%>

Add the session OnEnd event to the global file, application ("Isuserlogin") when offline =false
In addition, to detect whether puppet, there is a special way, is a server object in the

(Ginseng: http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=815)

2. Database +asp
It may be more complicated to do, but it is suitable for systems with a large number of landing users.

First create a database for users-create a new onlytol8.mdb with access

Data table 1:users Store user registration data
Under Data table: UID (AutoNumber) userName (character type) Userpass (character type)

Data Table 2:onlylogin Store user temporary login information
Under Data table: Olname (character) oltime (date type) olip (character type)

After the database has been built, add the data directly to the users table by manually adding the username table Tol8,userpass Add 111,

Below to do user login interface, copy the following code to save as onlylogin.asp file.

The following are the referenced contents:

<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> prohibit the same account in different areas at the same time login </title>
<body>
<form name= "Form1" method= "Post" action= "loginpost.asp" >
User name: <input name= "UserName" type= "text" id= "UserName" size= "maxlength=" "5" >
Password: <input name= "userpass" type= "password" id= "Userpass" size= "" "Maxlength=" >
<input type= "Submit" name= "Submit" value= "Login" >
</form>
</body>

When you are done, copy the following code in a new loginconn.asp file to save the connection database

The following are the referenced contents:

<%
Dim Conn_tol8
Dim conn_t
Dim MMDD
Mmdd= "Onlytol8.mdb"
Set Conn_tol8 = Server.CreateObject ("ADODB. Connection ")
conn_t= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath ("&mmdd&")
On Error Resume Next
Conn_tol8. Open conn_t%>

Below do a loginpost.asp file also exists in this directory, which is key, look carefully at the following code:

The following are the referenced contents:

<!--#include file= "loginconn.asp"-->
<%
"Delete MaxTime time internal activities of the user, maxtime in the loginconn.asp file has been defined well
Conn_tol8. Execute ("Delete from Onlylogin where DATEDIFF (' s ', Oltime, Now ()) >" & MaxTime & "")
''================================================================
Dim RS, TS, txt, SQL, userName, Userpass
If Request.Form ("Submit") = "Login" Then
Username=request.form ("UserName") "Get form User login name
Userpass=request.form ("Userpass") ' Gets the form user login password
"Because we're not talking about security here, the user's password is not encrypted.
Set rs = Server.CreateObject ("ADODB.") RECORDSET ")
Sql= "SELECT * from users where userName = '" & UserName & "' and Userpass = '" & Userpass & "" "
Rs. Open SQL, conn_tol8,1,1
IF not rs.eof Then
Call IsOK (userName) ' username password calls the secondary procedure correctly, IsOK will be customized in the following program.
Else
Response.Write ("<a href=javascript:history.go ( -1) > Username or password error </a>")
Response.End ()
End If
Rs. Close
Set rs=nothing
End If
Sub IsOK (UserName)
Dim olip ' Database current login username saved IP
Dim oltime ' Database The last time a page is saved in the current login username is an important data that calculates whether the user is online.
Dim OLip1 ' records the current user login IP, used to differentiate between the identity of the same user
Olip1=request.servervariables ("remote_addr") ' Gets the IP of the user who submitted the login information
Set Ts=conn_tol8.execute ("select * from Onlylogin WHERE olname=" "& UserName &" ")
If not ts.eof then ' queries the database for information about this user's login
Oltime=ts ("Oltime")
Olip=ts ("Olip")
If Olip1<>olip and DateDiff ("s", Oltime,now ()) < MaxTime Then
"To judge if a login user IP is not the last recorded user IP in the database and
"The user's last active time and current time are not over the specified number of seconds to confirm that this user is currently online
Response.Write "<a href=javascript:history.go ( -1) > This user is currently online and you cannot login to this account from anywhere else! </a> "
Response.End ()
Else
"Otherwise, the decision of landing successfully paid the value to the session
Session ("Lgname") =username
Session ("Lgpass") =userpass
Response.Redirect "Loginok.asp"
Response.End
End If
Else
"If the database does not log in to the user record, execute the following statement
Dim ls
Set ls=server.createobject ("ADODB. RECORDSET ")
Ls. Open "SELECT * from Onlylogin", conn_tol8,2,2
Ls. ADDNEW
LS ("Olname") =username
LS ("Olip") =olip1
LS ("Oltime") =now ()
Ls. UPDATE
Ls. Close
Set ls=nothing
"The decision landed successfully pay the value to the session
Session ("Lgname") =username
Session ("Lgpass") =userpass
Response.Redirect "Loginok.asp"
Response.End
End If
End Sub%>

After successful landing, the leaf will jump to loginok.asp

The following are the referenced contents:

<style type= "Text/css" >
<!--
Body {background-color: #FF9900;}
-->
</style>
<% IF session ("Lgname") <> "" Then%>
You landed a successful!!! Below is a sneak dive into the Web page to refresh the page at the specified time to report to the server whether you are online
For ease of distinction, frame Web pages We use white as the background
<iframe border=0 name=new_date marginwidth=0 framespacing=0 marginheight=0 src= "loginFrame.asp"
frameborder=0 noresize width=100 scrolling=no height=30 vspale= "0" ></iframe>
<% Else%>


You did not land ha

The following are the referenced contents:

<% End If%>

The next thing to do is loginframe.asp

The following are the referenced contents:

<!--#include file= "loginconn.asp"-->
<% Conn_tol8. Execute ("Update onlylogin Set oltime=" "& Now () &" ' where Olname = ' "& Session (" Lgname ") &" ""%>

This is the end of the program, the key to the program is to determine whether the user online.



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.