Online headcount Statistics Insider

Source: Internet
Author: User
Tags count sessions
Statistics | online | Number Like most of us 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 a example of the script we ' ve Goi  Ng to cover in this article. It ' s The little line at the top of these pages saying something like "There are users currently on this site!"  It ' s sort of cute and it gives you to the how many people are using the site.  I ' ve even seen one go so far as to show your a list of where people are on the site. While it's not something so we ' ve chosen to implement, there seems to is enough interest that we thought we should addre  SS 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 are just said we were going to count active users. Are you what exactly is a 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-I-visits when the user ended  Es.  HTTP doesn ' t work this way.  The connection is made, the request for the "page is sent", and the connection is dropped.  This is makes getting the number of people currently "on" a site rather difficult.  You are 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 the back and request another the page or not until they does or until you D Ecide ' ve waited long enough that they aren ' t going to!

Here comes ASP with a solution!

The session Object.  all the Sessions object does is provide us with a temporary storage area on the server for E Ach 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 your close your Browser.  unfortunat Ely, because the session object relies on cookies, if a visitor ' s browser doesn ' t support them or has them turned off, EAC H request is looked upon as a new sessions and can cause problems for a site which uses a lot of sessions 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-script too much and haven ' t used it. The good news is, "for" most part, the fear associated with cookies has been somewhat lessened through user Educati On 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 we discussion to a very special file on your Web Project:global.asa.  global.asa is the file Defines a web application.  it contains special scripts called event Handlers.  there are four such SC Ripts possible with the current version of Asp.  these are Application_OnStart, Session_OnStart, Session_OnEnd, and application_onend.  the Application_OnStart The script is called when you start the Web application by re Questing the "the" the "the" the "the" It.  the Application_OnEnd occurs the Web server (shut May n OT be called if the "server freezes up or loses power".   as you might from now, expect when A user requests their The page.  but when does Session_OnEnd run?  the event onend when the Session ends which can occur in a couple different ways.  the the "I" can call the Abandon method of T He session object which WIll kill the session immediately.  the second are you can the "session to Timeout.  this'll t Ake however many minutes you ' ve set the Session.Timeout property to.   (the ' s. If no one ' changed it.    naturally, it's more desirable to call Session.Abandon and have's session destroyed immediately and F Ree up the resources it uses instead of the letting it use them for minutes.

Now to our user count!

Like I mentioned earlier most of the "code for" particular script needs to go into your Global.asa file. For reference, I ' m including a Global.asa, which includes all the pieces needed to get this script working, below:

Global.asa:
<script language= "VBScript" runat= "Server" >

Sub Application_OnStart
' Set we ' user count to 0 when we start the server
Application ("Activeusers"



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.