欢迎光临
我们一直在努力

用asp显示当前在线用户信息,不是简单只显示人数那种![1]

建站超值云服务器,限时71元/月

东子 于 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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 用asp显示当前在线用户信息,不是简单只显示人数那种![1]
分享到: 更多 (0)