Good mourning or Good night ;)
i am working on asp site (VBscript)
of course with javascript as client side
i wanna 2 count n of visitors at same page
just like when u open for ex asp forum in daniweb.com
displays
Currently Active Users browsing ASP : 7 (1 members & 6 guests)
what ever by count sessions or what ever
i want easy and flexible method
:icon_biggrin:

Dani AI

Generated

: good question. pointed in the right direction by insisting on server-side tracking, but relying only on global.asa/session-end is brittle (process restarts, timeouts and tab closes make counts inaccurate). A robust pattern that works with Classic ASP is a short client heartbeat plus a server-side "last_seen" per page; count rows with recent timestamps to get active users per page.

Suggested schema and counting query (generic):

-- table: ActivePageViews
page_key    VARCHAR(200)    -- unique page identifier (URL or ID)
sid         CHAR(38)        -- client session id (cookie you set)
user_id     INT NULL        -- logged-in member id, null for guests
last_ping   DATETIME        -- last heartbeat time

-- count active on page within timeout (e.g. last 120 seconds)
SELECT COUNT(*) FROM ActivePageViews
 WHERE page_key = @page_key
   AND last_ping >= DATEADD(second, -120, GETDATE());

Client/server workflow (minimal):

  • On first visit set a short-lived cookie (pv_sid) with a generated GUID.
  • On page load and every N seconds (30-60s) send an AJAX POST to page_ping.asp?p=page_key to update last_ping for that sid+page.
  • Server-side page_ping.asp does: UPDATE ActivePageViews SET last_ping = Now() WHERE page_key=? AND sid=?; if no row updated then INSERT a new row (include user_id when logged in).

Troubleshooting and tips:

  • Use a heartbeat interval of 30-60s and a timeout about 2x-4x that interval to avoid flapping.
  • Require the JS heartbeat so non-JS bots are ignored.
  • Reduce DB load by only updating when last_ping is older than X seconds.
  • Periodically delete old rows (older than a day) or use a background job.
  • For high traffic move storage to an in-memory store (Redis/memcache) or carefully use Application-level structures to avoid locking.

This pattern gives accurate, per-page counts (members vs guests by presence of user_id) and avoids relying on session-end events.

Recommended Answers

All 2 Replies

help please ........!!!!!!!!

Hi Mohamed,
First, use global.asa to put every visitor into a table and assign them a unique ID. The count of the records is the number of the total visitors.

Once a visitor logs in, you assign him a member tag (e.g. a field in the database: member [yes/no]). Now you can count the number of the members.

The guests are the total number of visitors reduced by the number of the members.

Good luck,
Ali Baradaran

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.