473,623 Members | 2,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7073
.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=$times tamp-6000;

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

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

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

$result=mysql_q uery("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=$times tamp-6000;

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

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

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

$result=mysql_q uery("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, "RavenSlay3 r" <ra*********@gm ail.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("IN SERT 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_sav e_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
1742
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: <frame src="http://fotozine.org/.... what can I do to stop such things? not just for this particular person and his site, but in genaral? (sorry on my clumsy english)
1
1670
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 at-least count the customers or visitors in my "Store" (only in store), users of the other sections should not be counted. Whenever a user in my store signs out or closes the
5
3616
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 three. Upon closing two, each having separate sessions (and session ID's of course), the count remains at three! I'm not looking for alternative ways of doing this: I'm interested in knowing why the application variable does not get reduced...
3
3126
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 could be a security issue if they keep the computer unattended. Thanks for the help, Shahid
7
1353
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"--> <!--#include file="WEB_2.asp"--> "WEB" varies and is an acronym for a client's or site's name.
10
3330
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 doesn't realize it unless he looks at the opener page's source code. I'm wondering if there's a javascript solution for this? I've tried using the window.opener.location.replace with the href being my absolute URL, and triggered by an onUnload...
64
4233
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 am viewing at 800x600 right now by the way, because that's what I can comfortably see. Times New Roman default pitch is what - 12px? With people increasing their screen resolutions, is it possible for "default size to ever become too small in...
2
1740
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 site management. the popup is fired by a javascript function, when they click the site management link. there's also a "window close" function button so they can nuke it as they please. now, oddly, people who search for my site in the chinese...
71
4812
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? http://www.review-a-gadget.com/ Is there anything obvious that I am missing? Are there problems with some browsers? Please let me know if you notice anything.
0
8227
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8165
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8613
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8326
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7150
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6106
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4164
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1778
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.