首页 | 免费域名 | 个人服务器 | 一流信息监控拦截系统 | 虚拟主机知识库 | ASP 空间 | ASP技术大全 | 下载中心 | 客户服务中心
  7i24 > ASP技术大全 > 代码乐园 >
    7i24 .Com  
  现在你的站点上有多少访问者?

7i24.Com不停为您服务
现在你的站点上有多少访问者?

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

Application变量说明

Application变量同Session变量相类,所不同的是Application变量的值对所有的用户都是相同的,Session变量对每位用户都是不同的. 系统为每位用户建立他们的
Session变量的实例. 在服务器启动时,系统建立唯一的Application变量. 希望这些概念对理解下面的代码有利.



文件: Global.asa

<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Sub Application_OnStart
' Sub Application_OnStart is the procedure that fires
' everytime your server starts up.


' 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
</SCRIPT>


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

<%
 response.write "Are Now " & Application("WhosOn") & " users at
this page."
%>

编程快乐!



  2002年1月9日  阅读 1707 次  发送此页给朋友  来源:    版权争议  删除

相关文章:   近期热点:

上一篇: 来访者地址统计,很好的一个程序!
下一篇: 准确统计在线用户数量!
返回上一层...
搜索:

(C)2004-2022 7i24.Com 保留所有权利