博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
现在你的站点上有多少访问者(转)
阅读量:2496 次
发布时间:2019-05-11

本文共 1960 字,大约阅读时间需要 6 分钟。

要得知现在你的站点上有多少个访问者是很简单的,既使你从来没有用过global.asa,也甭发愁,要把下面我所写的代码放到你的网站的根目录下(譬如
www.yourpage.com/global.asa). 如果你对lobal.asa不熟悉,那还得先细细读一下这篇文章. 现在你所要做的是在每位新访客问你的站点时增加计数,在他们离开后减少计数,并写代码将计数显示出来.

Application变量说明

Application变量同Session变量相类,所不同的是Application变量的值对所有的用户都是相同的,Session变量对每位用户都是不同的. 系统为每位用户建立他们的

Session变量的实例. 在服务器启动时,系统建立唯一的Application变量. 希望这些概念对理解下面的代码有利.

文件: Global.asa

' Here you want to define the time that the user
' will be valid as on-line. (If no activity occurs
' for x minutes, then log the user off (erase his
' session variable instances))
Session.Timeout = 3

' The .Lock method locks the Application variable so that
' you can work on it. If you don't lock it there won't be
' any changes on the variable "WhosOn"
Application.Lock

' Start the variable at 0,

Application("WhosOn") = 0

' You now need to unlock the application

Application.UnLock
End Sub
Sub Session_OnStart
' Sub Session_OnStart is the procedure that works
' everytime a new user enters in your page

' Here is the place where you increment the number
' of users on your page (don't forget to Lock/Unlock
' your Application variable!) :)
Application.Lock
Application("WhosOn") = Application("WhosOn") + 1
Application.UnLock
End Sub
Sub Session_OnEnd
' Sub Session_OnEnd is the procedure that works
' everytime a user quits the page, this is defined n
' minutes after he quits.
' This n minutes are defined by the Session:Timeout in
' Sub Application_OnStart

' So... when a user quits there will be one less user, so
we
' decrement one on the "WhosOn" variable (don't
' forget to Lock/Unlock your application variable! :)
Application.Lock
Application("WhosOn") = Application("WhosOn") - 1
Application.UnLock
End Sub

文件: main.asp
下面的代码将实时地显示给你的站点的每位访客有多少用户在线:

 response.write "Are Now " & Application("WhosOn") & " users at

this page."
%>

编程快乐!

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-124702/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10294527/viewspace-124702/

你可能感兴趣的文章
python ssh
查看>>
工作笔记一——杂项
查看>>
查看apk包名和Activity的方法
查看>>
MPU6050开发 -- 卡尔曼滤波(转)
查看>>
Redis主从实战
查看>>
plsql if
查看>>
LuoGu P2002 消息扩散
查看>>
linux 下安装JDK
查看>>
简单的ASP.NET无刷新分页
查看>>
宏定义学习
查看>>
omitting directory `folder/'
查看>>
JavaScript面试题
查看>>
TCollector
查看>>
我的博客网站开发6——博文关键字搜索
查看>>
vim7.1在windows下的编码设置[转]
查看>>
同步器之Exchanger
查看>>
IO流
查看>>
专家观点:即使在云中 硬件同样至关重要
查看>>
loadrunner11录制不成功解决方法(收集)
查看>>
jQuery 基础
查看>>