Solved

visitor counter for specific page

Posted on 2010-11-28
7
341 Views
Last Modified: 2012-05-10
i want to show how many people are currently viewing the website and how many people are currently viewing the specific page user has opened.

i do have script for showing status for current visitors on website, but i am not sure how to display number of visitors viewing the specific page a particular user is displaying.
0
Comment
Question by:nandananushil1
  • 4
  • 3
7 Comments
 
LVL 3

Accepted Solution

by:
roynaufal earned 250 total points
ID: 34224852
check out this link, very straightforward and clear tutorial:
http://www.webdesign.org/web-programming/php/php-live-counter-online-users.8622.html

the concept in that is based on a user's ip, you can alternatively use session ids to be even more accurate (in case several people are on the same network, the website sees them coming from the same ip)
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 34225382
To get accurate counts (the kind that are useful for client measurement and reporting) you might want to use Google Analytics.

If you have a script showing the status of current visitors, it is almost certainly giving you an approximation.  The reason is that you have no way of knowing when a visitor "leaves" your site.  That's the nature of the client-server model.  A client makes a request and the server responds.  End of story.

You might make a reasonable assumption, like saying "anyone who loads a page on my site will remain on the page for 1 minute" and then you can write the programming this way...

Create the "activeUsers" table with DATETIME, pageName, userId

At page load time, start the session FIRST and then retrieve the session id. http://us2.php.net/manual/en/function.session-id.php
INSERT into activeUsers the values of NOW(), $_SERVER["PHP_SELF"], and the session id.
DELETE FROM activeUsers WHERE the DATETIME column is more than 1 minute old.
SELECT COUNT(*) FROM activeUsers WHERE pageName = $_SERVER["PHP_SELF"] - to get the count of users on this page.
SELECT COUNT(*) FROM activeUsers with no WHERE clause - to get the count of users on the site.

This table will never be very big, and these four queries will be so fast you will never even notice the time it takes to run them.
0
 
LVL 3

Expert Comment

by:roynaufal
ID: 34225399
yea, just like the above link, then you add a way to delete the entries based on that assumption

for live analytics, i would suggest woopra.com
it's one of the best live
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34225520
Interesting -- I had never heard of woopra.  What makes it stand out from Google Analytics?
http://www.woopra.com/plans/
0
 
LVL 3

Expert Comment

by:roynaufal
ID: 34225547
woopra shows the analytics live,
last time i checked google analytics was not live...not sure nowadays though
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34225563
Yeah, looks like it has a nice-looking dashboard, too.  GA is historical.
0
 
LVL 3

Expert Comment

by:roynaufal
ID: 34225577
yea, try it out :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now