Solved

Counting the number of Visitors to my pages

Posted on 2002-06-18
11
181 Views
Last Modified: 2006-11-17
I have several pages in PHP. I want to know how many visitors are browing these pages at any point of time. This information would be displayed on the opening page. How do I do it? Please can you give me the code for getting this done?
0
Comment
Question by:chaiti_c
11 Comments
 

Expert Comment

by:vk1981
ID: 7091892
U must insert a counter code on each php page. So the counter code will collect data about your visitors and write into file (for example counter.txt). On the main you must insert another script to get data from file and display on the screen.
0
 

Author Comment

by:chaiti_c
ID: 7092130
But the counter should decrease as the visitor leaves the page and increase as soon as another user enter. How do I do it???
I have MySQL database as the backend
0
 

Expert Comment

by:vk1981
ID: 7092233
OK, you must generate unique id for every visitor and put this id and time into database. Do this for each page.

On the main page your script must calculate all visitors (using unique id), who visited your site for example last 30 min (or 5 min).

Also u can use sessions besides unique id.
0
 
LVL 5

Expert Comment

by:dkjariwala
ID: 7092394
Try a site like

http://www.extreme-dm.com/

Its much better choice. cause they have everything setup, and your server doesnt get burdened.

JD
0
 
LVL 5

Expert Comment

by:Hamlet081299
ID: 7094249
It is tricky - It's easy to know when someone starts to look at a page, but if they close the browser, or go to another website, how can you know they have left???
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.

 

Author Comment

by:chaiti_c
ID: 7094783
No problem in generating a unique number for each visitor but how do I trap when a visitor enters my site and also keep a track of when the visitor leaves. What is the code for trapping the visitor when he enters the site and also to trap the moment he leaves.
Can someone please send the code???
0
 

Expert Comment

by:vk1981
ID: 7094979
There is no need to use any difficult scripts. When a visitor enters your page, you just generate a unique id and send cookie with this unique id, so when user enters another page on your site you get this cookie and insert into the database (insert: unique id, time and page). So you always know which page the visitor enters.

But when the visitor leaves your site ... ;) - this is a big problem to the script. So to resolve it display only those users who visited your site (or some page) last 30 min.


0
 

Author Comment

by:chaiti_c
ID: 7094993
I need to give the exact number of visitor at any given point of time and so just checking how many visitors there are in the last 30 minutes won't help.
0
 

Expert Comment

by:vk1981
ID: 7094998
Also u can use something like this:
....
<Body onUnload="window.open('leaves.php')">
...

// leaves.php starts
<?
   $counter --;

?>
<script language="javascript">
   window.close ();
</script>
// ends

This method works good only for u but for your visitors...
0
 

Accepted Solution

by:
vk1981 earned 300 total points
ID: 7095000
It's imposible... :(
0
 

Expert Comment

by:vk1981
ID: 7095025
All counters over the world use its own algorithm to calculate visitors numbers, but noone can do it correct :(
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

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
The viewer will learn how to dynamically set the form action using jQuery.

914 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