东子 于 00-9-3 上午 02:35:55 发表在:asp地带
global.asa 放在你的根目录
<object runat="server" scope="application"
id="rstactiveusers" progid="adodb.recordset">
</object>
<script language="vbscript" runat="server">
the first thing you should notice is the top line.
it creates an application scoped recordset object
named rstactiveusers that ill use to store all
our user information.
note: ive wrapped it for readability
sub application_onstart()
selected constants from adovbs.inc
const adinteger = 3
const advarchar = 200
const addate = 7
here i set up in memory active user recordset
by adding the fields i want to it and defining
their data types.
rstactiveusers.fields.append "id", adinteger
rstactiveusers.fields.append "ip", advarchar, 15
rstactiveusers.fields.append "browser", advarchar, 255
rstactiveusers.fields.append "started", addate
next i open our recordset so that we can use it.
that basically gets everything ready for our
first user.
rstactiveusers.open
end sub
sub session_onstart()
set session timeout to 20 minutes
session.timeout = 20
set a session start time. this is pretty pointless,
but it does ensure that we start a session and
assign the user a session id and it can help
troubleshooting if we ever need it.
session("start") = now()
move to the end so records are added in order.
again not of any real importance, but it keeps our
user table nice and orderly.
if not rstactiveusers.eof then rstactiveusers.movelast
add a record and insert users data. im just
storing some basic info, but naturally youre free
to store whatever you want.
rstactiveusers.addnew
rstactiveusers.fields("id").value = _
session.sessionid
rstactiveusers.fields("ip").value = _
request.servervariables("remote_host")
rstactiveusers.fields("browser").value = _
request.servervariables("http_user_agent")
rstactiveusers.fields("started").value = _
now()
rstactiveusers.update
now that weve got the information, all thats
left is to display it. see test_page.asp for a
demo. it includes the pages show_count.asp and
show_users.asp which can also be used
individually if desired.
end sub
sub session_onend()
selected constants from adovbs.inc
const adsearchforward = 1
const adbookmarkfirst = 1
const adaffectcurrent = 1
find the appropriate record. using session id is the
easiest way since i use this as the primary key.
this line positions us on the appropriate record.
rstactiveusers.find "id = " & session.sessionid, _
0, adsearchforward, adbookmarkfirst
now that were on the record, delete it.
i use the eof to make sure weve got one.
if not rstactiveusers.eof then
rstactiveusers.delete adaffectcurrent
end if
end sub
