在线人数统计内幕

2016-01-29 19:37 6 1 收藏

在线人数统计内幕,在线人数统计内幕

【 tulaoshi.com - ASP 】

       在线人数统计内幕
  
  Like most of our topics, I''m covering this one due to user demand for it. If you''ve been to any one of a few dozen ASP-based sites recently, you''ve probably seen an example of the script we''ve going to cover in this article. It''s the little line at the top of these pages saying something like "There are 28 users currently on this site!" It''s sort of cute and it gives you an idea of how many people are using the site. I''ve even seen one go so far as to show you a list of where people are on the site. While it''s not something that we''ve chosen to implement, there seems to be enough interest that we thought we should address it. Normally I''d cover a topic like this in a sample, but since the bulk of this code needs to go into your global.asa file, I thought I should probably give a more in depth explanation.
  
  What are we counting?
  
  It seems to be a silly question. After all, we just said we were going to count active users. Well what exactly is an active user? A connection using HTTP (the protocol of the web) isn''t like other connections. FTP, Telnet, E-mail, and most other types of connections are started when a user first visits and ended when the user leaves. HTTP doesn''t work this way. The connection is made, the request for the page is sent, and the connection is dropped. This makes getting the number of people currently "on" a site rather difficult. You don''t have a connection to everyone so you can''t simply count them. You also have no way of telling if they''re going to come back and request another page or not until they do or until you decide you''ve waited long enough that they aren''t going to!
  
  Here comes ASP with a solution!
  
  The Session object. All the Session Object does is provide us with a temporary storage area on the server for each user. It keeps track of which user belongs to which storage area by using cookies. These cookies never have their expiration property set and as a result, expire as soon as you close your browser. Unfortunately, because the Session object relies on cookies, if a visitor''s browser doesn''t support them or has them turned off, each request is looked upon as a new session and can cause problems for a site which uses a lot of Session objects or does a lot of processing in Session_OnStart. It also causes a script like this to count every hit as a session! This is the main reason we don''t like this script too much and haven''t used it. The good news is, that for the most part, the fear associated with cookies has been somewhat lessened through user education and the number of users who go out of their way to turn cookies off has decreased significantly.
  
  ASA, I thought they were ASPs!
  
  This brings our discussion to a very special file in your web project: global.asa. Global.asa is the file that defines a web application. It contains special scripts called event handlers. There are four such scripts possible with the current version of ASP. These are Application_OnStart, Session_OnStart, Session_OnEnd, and Application_OnEnd. The Application_OnStart script is called when you first start the web application by requesting the first .asp file from it. The Application_OnEnd occurs when you shut down the web server (but may not be called if the server freezes up or loses power). As you might expect by now, Session_OnStart occurs when a user requests their first ASP page. But when does Session_OnEnd run? The OnEnd event runs when the session ends which can occur in a couple different ways. The first one is you can call the Abandon method of the Session object which will kill the session immediately. The second is you can wait for the session to timeout. This will take however many minutes you''ve set the Session.Timeout property to. (The default is 20 if no one''s changed it

来源:https://www.tulaoshi.com/n/20160129/1509792.html

延伸阅读
标签: Web开发
在浏览网页的时侯,常常可以看见一些当前网站上的人数是XXX人的在线人数同计。如何用ASP来做一个呢?首先,分析一下它的做法,一般来说,这些线上人数统计都是指一个时段内的访客人数统计。比如(5分钟内,10分钟内)而这个时间的长短,是由设计者设定的。 在这个时段内同计各个不同IP的访客总数,就可以得出当前的线上人数了,...
标签: ASP
  最普通的方法是用SESSION,但缺点是无法即时反应在线情况(有超时时间)和占用服务器资源(如果有100人在线就有100个SESSION,想想看8);上次(好象间隔很久了耶)介绍了一种采用APPLICATION+COOKIES的方法,但实现方法有些烦琐同时还要设一个隐藏的自刷新页面。 这种方法则避免了以上的弊病,经实践,效果不错(例子:WWW。ATERSOFT。...
标签: ASP
  count.asp: <%Server.ScriptTimeout=300 id=Trim(Request.QueryString("id")) fc=Trim(Request.QueryString("fc")) if fc="" then fc="FFFF00" bg=Trim(Request.QueryString("bg")) if bg="" then bg="000000" bc=Trim(Request.QueryString("bc")) if bc="" then bc="00FF00" sername=Request.ServerVariables("SERVER_NAME") scrn...
标签: PHP
  可以实现在线人数统计,日访问量统计,月访问量统计。。。。。 <? $sql = "CREATE TABLE guestinfo(id integer DEFAULT '0' NOT NULL       AUTO_INCREMENT,                    &nbs...
标签: PHP
  这是我的多用户统计的在线统计部分 gb_temp表: temp1 用户ID temp2 流览IP地址   temp3 online//做了个标记,因为其他功能也要使用这个表 temp4 登陆时间 $onlinetime最长离线时间分钟 db_class是我定义的一个数据库操作类。 /////////////////// //在线统计 $db = new db_class; $db-connect(); $limit_time...

经验教程

206

收藏

30

精华推荐

微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部