473,406 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

counting CURRENT site visitors

Hello,

I am developing a site using php and mysql and I would like to be able to
let visitors know how many other visitors are currently browsing the site
i.e. 'There are currently x amount of visitors browsing this site'

You can see this in action in the following sites but I am not sure what
technology they use www.recruitni.com (about 1/3 down the page) and also
www.scancom.co.uk on the left hand side.

Is this possible using PHP and can anyone point me in the direction of how
to achieve it?

Thanks.

td

http://www.pocketpcheaven.blogspot.com/

Jul 17 '05 #1
5 7045
.oO(toedipper)
I am developing a site using php and mysql and I would like to be able to
let visitors know how many other visitors are currently browsing the site
i.e. 'There are currently x amount of visitors browsing this site'
If you want the value to be accurate -- impossible.
You can see this in action in the following sites but I am not sure what
technology they use www.recruitni.com (about 1/3 down the page) and also
www.scancom.co.uk on the left hand side.


HTTP is a stateless protocol, there's no way to determine how many
visitors are currently "online", because there simply is no way to
identify unique users except for an explicit login. It's all based on
estimations (for example the amount of requests from different IPs in
the last 10 minutes) and as useless as a hitcounter for a visitor. The
number of currently browsing users or page hits says absolutely nothing
about a site's quality.

Micha
Jul 17 '05 #2
On Sat, 22 Jan 2005 22:50:05 -0000, "toedipper"
<se******************@hotmail.com> wrote:
I am developing a site using php and mysql and I would like to be able to
let visitors know how many other visitors are currently browsing the site
i.e. 'There are currently x amount of visitors browsing this site'


For my website I use this method...

$timestamp=time();

// 10 minutes of timeout
$timeout=$timestamp-6000;

mysql_query("INSERT INTO online (time,ip) VALUES
('$timestamp','$REMOTE_ADDR')");

// purge all old users
mysql_query("DELETE FROM online WHERE ora < $timeout");

// delete my own ip adress from statistic
mysql_query("DELETE FROM online WHERE ip = 'xxx.xxx.xxxx.xxxx'");

$result=mysql_query("SELECT DISTINCT ip FROM online");
$user=mysql_num_rows($result);

echo $user;


Jul 17 '05 #3
Nearly exactly what I was going to say Ghizmo.

The simpliest way is to write a script that inserts (or updates) the IP
and Time/date in a DB table. Then count the # of unique IP's and puge
the old one's. Most sites look at a 10 min. interval for this purpose;
given the nature of HTTP.

Call [the file] "userCount.php" or somthing and include it at the top
of your header so it's called on every page hit.

------
I'm going to modify Ghizmo's code to show what I was thinking. Haven't
tested this but I'm 99% sure it's right (and more efficent).

REPLACE should INSERT the value if the record doesn't exist and DELETE
& INSERT if it does, keeping the IP coloumn unique.

(if you try this let me know how it works.)

------
// ** Begin userCount.php **//

$timestamp=time();

// 10 minutes of timeout
$timeout=$timestamp-6000;

// REPLACE instead of INSERT
mysql_query("REPLACE INTO online (time,ip) VALUES
('$timestamp','$REMOTE_ADDR')
WHERE ip = '$REMOTE_ADDR')";

// purge all old users
mysql_query("DELETE FROM online WHERE time < $timeout");

// delete my own ip adress from statistic
mysql_query("DELETE FROM online WHERE ip = 'xxx.xxx.xxxx.xxxx'");

$result=mysql_query("SELECT ip FROM online");
$user=mysql_num_rows($result);
echo $user;

// ** End userCount.php **//

Jul 17 '05 #4
On 23 Jan 2005 01:26:40 -0800, "RavenSlay3r" <ra*********@gmail.com>
wrote:
Nearly exactly what I was going to say Ghizmo.
REPLACE should INSERT the value if the record doesn't exist and DELETE
& INSERT if it does, keeping the IP coloumn unique.


Thanks Raven for completing my script. The reason of the Insert in my
script is because I it to keep track of all the movments in my
website. My complete Query is

mysql_query("INSERT INTO online (time,ip,where) VALUES
('$timestamp','$REMOTE_ADDR','$PHP_SELF')");

and keep records for 24hours instead of 10 minutes.
So I can see exactly where the user moves.

Bye bye
Salutoni,
Ghizmo
---------
-----------
------------
Webmaster di
www.agenziaoksana.com
---------------------

Jul 17 '05 #5
toedipper wrote:
Hello,

I am developing a site using php and mysql and I would like to be able to let visitors know how many other visitors are currently browsing the site i.e. 'There are currently x amount of visitors browsing this site'

You can see this in action in the following sites but I am not sure what technology they use www.recruitni.com (about 1/3 down the page) and also www.scancom.co.uk on the left hand side.

Is this possible using PHP and can anyone point me in the direction of how to achieve it?


This is much easier if you use custom DB based session handler
<http://in.php.net/session_set_save_handler>

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Fotozine | last post by:
well, after several months of learning, writing and developing my site, (and colecting hunderts of users in few days) one person have "included" my whole site under his domain. in frameset: ...
1
by: Sajid | last post by:
Hi, I'm developing an online shopping cart. Usually the site administrator modifies products etc in the "Store". I want a mechanism for the administrator such that he should be able to view or...
5
by: cc | last post by:
From the popular website At this link: http://www.w3schools.com/asp/asp_globalasa.asp I got this code, but it does not work on my server... I can open three IE browsers and watch the count go to...
3
by: Shahid Juma | last post by:
Hi, Is it possible to get the current user that is logged on to the computer? I want to use this as the basis of my validation on the site instead of asking them to login in again. I know it...
7
by: McKirahan | last post by:
When developing a new site, I often use the following : <!-- This is page: WEB_Page.asp --> <!--#include file="WEB_0.asp"--> <!--#include file="WEB_1.asp"--> <!--#include file="WEB_Page.htm"-->...
10
by: Thad | last post by:
Any javascript I could try on this? I've got a popup window on my site with the browser chrome removed. Another site's gone ahead and done a popup to my same .html page. The visitor to that site...
64
by: Dave | last post by:
A friend of mine pointed out the other day that certain elements on my web site are too small. But in most of what I publish, fonts are at default size or smaller, and my images are easy to see. I...
2
by: Word Painter | last post by:
this may be more of an "html" issue, but I'll wing it. i've got a multi-language site, where the home-page of each language group features a link to a popup window that offers background info on...
71
by: Murray R. Van Luyn | last post by:
Hi, Since I have made changes to my website it's been a complete flop. According to the logs, as soon as visitors have downloaded the index page they are off. I can't figure out why? ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.