Control user Login to website and display online user list

Source: Internet
Author: User
Control | show | online
Here's what the Global.asa:

Sub Application_OnStart
' Delete All saved sessions information, in case of a crash
Set Objado = Server.CreateObject ("ADODB. Connection ")
Sdatabasepath = Server.MapPath ("/databases")
Sconnection
= "filedsn=" &sDatabasePath& "\readwrite.dsn;dbq=" &sDatabasePath& "\sessi"
Ons.mdb; "
Objado.open (sconnection)

Supdatecmd = "Delete * from session;"
Objado.execute (Supdatecmd)
' Close to the database down again
Objado.close
Set objado=nothing

' Now store the DSN connection string away and so we don ' t have to look
It up again
Application ("sessiondsn") = Sconnection

End Sub

Sub Session_OnStart

' Write The session information away to the session database
Set Session_objado = Server.CreateObject ("ADODB. Connection ")
Session_objado.open (Application ("SESSIONDSN"))
Session_supdatecmd = "INSERT INTO session values
("&Session.SessionID&", "
Session_supdatecmd = session_supdatecmd & "'" &request.servervariables
("REMOTE_ADDR") & "',"
Session_supdatecmd = session_supdatecmd & "'" &request.servervariables
("Http_user_agent") & "');
Session_objado.execute (Session_supdatecmd)
' Close to the database down again
Session_objado.close
Set session_objado=nothing

End Sub

Sub Session_OnEnd

' Delete The session information to the session database
Set Session_objado = Server.CreateObject ("ADODB. Connection ")
session_sconnection = Application ("Sessiondsn")
Session_objado.open (session_sconnection)
Session_supdatecmd = "Delete * from session where
Sessionid= "&Session.SessionID&"; "
Session_objado.execute (Session_supdatecmd)
' Close to the database down again
Session_objado.close
Set session_objado=nothing

End Sub

Here is an example of implementing functionality:

<% OPTION EXPLICIT

' Currentusers.asp V1.0
' Copyright 1998/99 Bann Consultants barryd@bann.co.uk
' Created 03/11/98 Modified 03/11/98
' On-line documentation at http://www.bann.co.uk/asp/
'
' COPYRIGHT NOTICE
' Copyright 1998-1999 Barry Dorrans all Rights Reserved.
'
' Currentusers May is used and modified free of charge by anyone so
Long
' As this copyright notice and the comments above remain intact. By
Using
' This code is for you agree to indemnify Barry Dorrans from any liability
That
' might arise from it use.
'
' Selling the code for this program without prior written consent is
' expressly forbidden. In the other words, before
Try and
' Make-money ' on my program.
'
' Obtain permission before redistributing this software over the
Internet or
' In no other medium. In the all cases the copyright and header must remain
Intact
%>

<title>current User report</title>
<body bgcolor= "#fffaf0" >


<br>
<table border=0>
<tr><td><p><b>remote host</b></td>
<td><p><b>Browser</b></td></tr>
<%

DIM Objado, Sdatabasepath, Sconnection, sessionrecords
DIM UserCount

UserCount = 0

SET Objado = Server.CreateObject ("ADODB. Connection ")
Sdatabasepath = Server.MapPath ("/databases")
Sconnection
= "filedsn=" &sDatabasePath& "\readonly.dsn;dbq=" &sDatabasePath& "\sessio"
Ns.mdb; "
Objado.open (sconnection)

SET sessionrecords = Objado.execute ("select * from session;")

Do as not sessionrecords.eof
UserCount = UserCount + 1
%>
<tr><td><p><%=sessionrecords ("Host")%></td>
<td><p><%=sessionrecords ("BrowserType")%></td></tr>
<% Sessionrecords.movenext
LOOP

Sessionrecords.close
Objado.close
SET sessionrecords = Nothing
SET objado=nothing

%>


The session variable's expiration date defaults to 20 minutes, and can be changed by its default expiration date:
session.timeout= (number of minutes of validity)



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.