ASP to determine the number of users login two

Source: Internet
Author: User
Tags current time file copy

ASP to determine how many users log in, anxious, how to judge not to let the same user name on multiple machines at the same time a system is completed in a new loginconn.asp file copy the following code to save to connect to the database

<%
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:

<!--#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 "This user is currently online, you can not login this account from other places!" "
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

<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
<% End If%>


The next thing to do is loginframe.asp

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


So the program is done, the key to this program is to determine whether the user is 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.