Classic ASP BasicsFor beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
I have designed a membership script.
it has also a last logon field which gets the date/time(now())
when user logs in.
now how can I write a code that shows which user is online at that time?
a user might login at 1 am but after a few hours this time remain in the db!
One way is to keep track of the users session.
In the global.asa file you can handle the event for Session_OnEnd. In that event handler you would place code that marks the users record in the database as being off-line, or to do whatever you need to change in your database (or whereever) that the user is no longer active in the systems.
Is there any way without global.asa
sth like this code StrOnlineTimedout = dateadd("n",-strtimeout*60,onlinedate)
that when a user logs on it shows him online until 1 hour(the period the session exipres)
Well... what exactly would StrOnlineTimedout be used to do?
Where is it declared - in which asp file? It is just a variable - what code is going to use it, and what will it do with it?
Why not use the global.asa? Perhaps I am misunderstanding you.
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
'This is a very simplistic example.
' Ths initializes the counter
Application("ONLINE_COUNT") = 0
' Use whatever timeout you want. This sets it to 1 minutes for test purposes
' so you can easily see the count go down as sessions are ended...
Session.Timeout = 1
' By setting a session variable when we first start a session we make sure that
' a session is actually started.
Session("STARTED") = Now
' Increment that counter that keeps track of users with an active session
Application("ONLINE_COUNT") = Application("ONLINE_COUNT") + 1
' Decrease the active visitors count when the session ends.
Application("ONLINE_COUNT") = Application("ONLINE_COUNT") - 1
and now a simple page to demonstrate:
' I named this page ShowCount.asp
s = "The count is: " & Application("ONLINE_COUNT") & "<br/>"†††
GetCount = s
†GetSessionStart = "I signed on at: " & Session("STARTED") & "<br/>"
<head><title>Count Users Test</title></head>
†<%=GetSessionStart %> †