Nov 22, 2009

How To Display XX Users Online On Your Site ?

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Designing > Web Design and HTML

How To Display XX Users Online On Your Site ?

valcarni
i've seen many sites around the net that have something on their page that says like 348 users online... does anyone here know how that is done and could help with this issue.... like i wish to record the number on users on all my 525 pages on my site and add them all together into 1 number that i show on the front page of my site (not just the ppl viewing that 1 page).... if anybody could help i'd be very thankful

thank you!

Comment/Reply (w/o sign-up)

szupie
I Googled around and found a solution. It requires PHP, which you'll be able to use if you're hosted here. Anyway, here's the code:

QUOTE
CODE
/* Start the session */
session_start();

/* Define how long the maximum amount of time the session can be inactive. */
define("MAX_IDLE_TIME", 3);

function getOnlineUsers(){

if ( $directory_handle = opendir( session_save_path() ) ) {
$count = 0;
while ( false !== ( $file = readdir( $directory_handle ) ) ) {
if($file != '.' && $file != '..'){
// Comment the 'if(...){' and '}' lines if you get a significant amount of traffic
if(time()- fileatime(session_save_path() . '\\' . $file) < MAX_IDLE_TIME * 60) {
$count++;
}
}
closedir($directory_handle);

return $count;

} else {
return false;
}

}

echo 'Number of online users: ' . getOnlineUsers() . '<br />';
Source: http://www.devarticles.com/c/a/PHP/The-Qui...nline-With-PHP/

The MAX_IDLE_TIME is counted in minutes. Basically, this code starts a session for every visitor of your site, and then, when the page is being processed, it counts the total number of sessions and outputs the number.

 

 

 


Comment/Reply (w/o sign-up)

Kushika
I use the following script:
CODE

<a href="http://www.fastonlineusers.com"><script src=http://fastonlineusers.com/online.php?d=www.YOURSITE.com></script> online</a><BR>


I got it from http://www.fastonlineusers.com it simple, and only requires a user to have JavaScript enabled in their browser. wink.gif

Comment/Reply (w/o sign-up)

Samya
QUOTE(Kushika @ Mar 4 2006, 04:15 PM) *

I use the following script:
CODE

<a href="http://www.fastonlineusers.com"><script src=http://fastonlineusers.com/online.php?d=www.YOURSITE.com></script> online</a><BR>


I got it from http://www.fastonlineusers.com it simple, and only requires a user to have JavaScript enabled in their browser. wink.gif



Hmmm ....
But what you have menioned is something different ...
It is actually a Remotely Hosted Script ...

Which means that all the Scripts are hosted on their Server and we only link them ...

But if u have the support for PHP and MySQL, than I think u should go for a Script on ur own Server ...

I am saying this, because it is a quite observable fact that Script hosted on some other Server will make ur website too slow ...
This is because, data is first transferred from ur Server and than from their Server as well ....

I think that u should go for ur own Script ...

Comment/Reply (w/o sign-up)

Samya
So here is a good PHP Script which u can use inorder to show Users Online Counter or simply Live Counter for ur Site.

Note :
U need a MySQL Database to use this script ....
This script only needs One Table, so u can use ur Database for other purposes as well ... smile.gif

So here we go .....

First we need to create the Tables in our DATABASE ...
Just run this query, in PHPmyAdmin, or anywhere u like smile.gif

CODE
CREATE TABLE `live` (
`idx` int(10) unsigned NOT NULL auto_increment,
`ip` varchar(15) NOT NULL default '',
`last_access` int(10) unsigned NOT NULL default '0',
`location` varchar(80) NOT NULL default '',
PRIMARY KEY  (`idx`),
KEY `ip` (`ip`),
KEY `last_access` (`last_access`)
) TYPE=MyISAM


After that u have created the tables ...
Save this page as anyname.php

CODE
<?php
// First of all, Connect to Database

$dbhost  = 'localhost';           // ur Database Host
$dbuser  = 'root';                 // ur username
$dbpass  = 'password';        // ur password
$dbname = 'databaselive';   // ur database name

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die    ('Error connecting to mysql');
mysql_select_db($dbname);

// gets the IP Address and saves it into Database
$ip = $_SERVER['REMOTE_ADDR'];
$now = time ();
$now_5 = $now - 300; // refresh every 5 min
mysql_query ("DELETE FROM live WHERE last_access < $now_5");
$res = mysql_query ("SELECT * FROM live WHERE ip='$ip' LIMIT 1");
if (!$row = mysql_fetch_array ($res)){
    mysql_query ("INSERT INTO live SET ip='$ip', last_access = '$now'");
}
else{
    mysql_query ("UPDATE live SET last_access = '$now' WHERE idx='$row[idx]' LIMIT 1");
}

// display the Live Counter

$txt = '';
$n = 0;
$res = mysql_query ("SELECT * FROM live");
while ($row = mysql_fetch_array ($res)){
$n++;
$txt .= "IP: $row[ip] - Last Access: ".date ('r', $row['last_access'])."<BR>";}
$txt = "There are/is $n visitor(s) now:<BR>".$txt;

echo $txt;

?>


Thats it smile.gif
ur Live Counter is Ready ...

However, u must have seen the Live Counters in Image Format, such as that of Bravenet etc ...
Just like this one ...

IPB Image


No Need to get Confused ...
Its really easy ...
All u need to have is that u should have GD Library installed in ur Server ....
It is available for free at :
http://www.boutell.com/gd/

If u are not sure whether GD Library is installed or not, than u should better ask ur Web Host ...
However there is also another option ....

Just save this file as gd.php or anything.php :

CODE
<?php
if (function_exists('imagecreate')) {
   echo "GD Library is enabled <br>rn<pre>";
   var_dump(gd_info());
   echo "</pre>";
} else {
   echo 'Sorry, you need to enable GD library first';
}
?>


Than upload this file to ur Web Server using FTP or anything ...
Point ur browser to this file, and open it ...
Thats it ....

If u see, GD Library is enabled .... it means that ur Web Server has got GD Library smile.gif
If u see, Sorry, you need to enable GD library first ..... it means, that ur Web Server dont have GD Library and this Image Script will not work ....


Anywayzzzz ... Moving further,
Save this file as anyname.php smile.gif

CODE


<?php

// First of all, Connect to Database

$dbhost  = 'localhost';           // ur Database Host
$dbuser  = 'root';                 // ur username
$dbpass  = 'password';        // ur password
$dbname = 'databaselive';   // ur database name

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die    ('Error connecting to mysql');
mysql_select_db($dbname);

header ('(anti-spam-(anti-spam-(anti-spam-(anti-spam-(anti-spam-(anti-spam-content-type:)))))) image/png');
$ip = $_SERVER['REMOTE_ADDR'];
$now = time ();
$now_5 = $now - 300;    

// refresh every 5 min

mysql_query ("DELETE FROM live WHERE last_access < $now_5");
$res = mysql_query ("SELECT * FROM live WHERE ip='$ip' LIMIT 1");
if (!$row = mysql_fetch_array ($res)){
    mysql_query ("INSERT INTO live SET ip='$ip', last_access = '$now'");
}else{
    mysql_query ("UPDATE live SET last_access = '$now' WHERE idx='$row[idx]' LIMIT 1");
}

// display the Count

$res = sql_query ("SELECT COUNT(*) AS num FROM live LIMIT 1");
$row = sql_fetch_array ($res);
$n = $row['num'];if ($n > 1){
    $txt = "There are $n visitors now.";
}else{
    $txt = "There is $n visitor now.";}

// calculate image size

$w = (strlen ($txt) * 7) + 41;
$h = 17;$gb = imagecreate ($w, $h);
$bg = imagecolorallocate ($gb, 255, 255, 255);
$fg = imagecolorallocate ($gb, 0, 0, 0);
$cy = imagecolorallocate ($gb, 19, 114, 108);
imagerectangle ($gb, 0, 0, $w-1, $h-1, $fg);
imagefilledrectangle ($gb, 2, 2, 35, 14, $cy);
imagestring ($gb, 3, 5, 1, 'LIVE', $bg);
imagestring ($gb, 3, 38, 1, $txt, $fg);
imagePNG ($gb);
imagedestroy ($gb);
?>


Credits

This article is actually written by me, (Samya Khalid) and is actually a modified version of one available at PHP Magix. I have added some information, and deleted some information which was redundant and beyond the scope of this topic smile.gif

You can see the Original Tutorial at :
http://magix.c97.net/read.php?15,1

*** All Criticisms and Appreciations are welcome ***

Regards:
Samya Khalid

Comment/Reply (w/o sign-up)

WeaponX
For the code that szupie posted above, what path should I give it?
QUOTE
session_save_path("/path/to/custom/directory");
I don't think my webhost have a dedicated server running...probably a shared.

Probably redundant question, but just to be sure, will this count all the visitors in the whole domain/site or just the page with the code in it?

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Display Xx Users Online Site

  1. Weather Feed Script In Php - A good weather feed on your site (2)
    If you are tired of providing your clients with weather feeds that take visitors off of their site
    or slam their site with ads, I finally found one after searching for hours. Here's a link to a
    FREE php script that pulls the feed directly from any airport in the world to your site. It is easy
    to customize and has simple, well documented installation instructions.
    http://www.mattsscripts.co.uk/mweather.htm hope you find it helpful... a good one for designers
    to archive as you will most likely need it some day for a client. Check out Matt's other free
    scri...
  2. IE6 display:block hides other image BUG - (1)
    Hi everyone, I have a problem. I have two images, and one has the 3px IE bug. Turning this to a
    block level element fixes it but then an image to the right disapears. Another fix I have tried is
    an IE hack with -3px margin which makes the bottom line up but then the top is off. Here is the
    CSS in question.
    code:--------------------------------------------------------------------------------#masthead {
    width:100%; background-color:#4F6DB1; background-image: url(../images/layout/blg_gradient.jpg);
    background-repeat:repeat-x; } #logo { position:relative; z-in...
  3. Website Navigation Hover Buttons Stick So Made Css Today - need further help with tutorial from this site (7)
  4. Find Out Dead Links In Your Site Automatically - Want to see a dead link on your site? (11)
    If you try to go to http://www.dead-links.com you will be asked for your domain or url. Enter it
    and the bot will find any dead links that you might not have seen. Have a nice day......
  5. Help me - I want to make site to the linux beginer (3)
    Please help me, give me ideas. I want to create a place to help to all the persons that want to
    learn linux. I have ideas but I now you have better ideas. My main idea is to show that everything
    that is done in windows can be done in linux. As see movies, play music and create sites webs....
  6. Redirecting All Htm Files To Php Site... - (8)
    Hi, just finished converting all my files from .HTM to .PHP files. Is there an easy way to redirect
    all my users who go to the .HTM pages to the .PHP pages instead? Basically all the names remained
    the same. Just the extension changed. My webhost has cPanel 10. something... Thanks....
  7. Flash Pic Problems - Pics Display at Low Resoution (7)
    Posted this in another section but this could apply here too. Can anyone help me with this problem
    I seem to be having with flash?? I know this is probably some stupid little setting somewhere I have
    to tweak but I can't find it. I'm trying to put a picture into flash on the canvas. I have a
    seperate layer for it. Nothing else is on the layer. Properties for the picture is set at 100 %
    quality. My publish settings are set at 100% quality for Jpegs and I've tried every setting I
    can find but the picture keeps displaying at a low resolution when I preview my m...
  8. Stretching My Site Vertically - Using CSS or HTML (6)
    I know it's possible, I've seen it one time. But I forgot. Many websites, if they hold more
    content than there is room for in the minimum height, the site stretches vertically. How can I do
    this? I only know that I need a background image of 1px height. Thanks in advance MediYama...
  9. Unicode Encoded Site - Characters Not Displaying Properly? - (4)
    Hey guys, I've been working on a AJAX based CMS for a client for the last few days
    and am in the final stages of deployment. I've run into a slight problem here. The site is
    supposed to be in Norwegian. The back-end uses the tinyMCE editor for adding in content, which
    is stored in MySQL. Now this presents no problem at all and the content is displayed just fine in
    the browser.. Problem arises when it comes to the site menu. It is a drop-down menu script from
    DynamicDrive, which reads off the menu items the same way from MySQL as the content and b...
  10. Cvs For Maintaining Your Site - (0)
    This is something every webmaster would love to use.. but didn't know existed. There is a tool
    named "CVS" which can be used to save all versions of your program. You initially start with a set
    of source code files, and the project grows from there on. If you make a mistake you can always
    restore the changes you made from the previous version you added to the "CVS". During a
    website's lifetime, a lot of code keeps changing, and more often than not, some code causes a
    problem in the rest of your website. Using CVS would help to detect where you slipped in those ...
  11. Free Online Cheatsheets - (2)
    Hi, I hope that the following links will be useful in the case you need an online quick reference
    of HTML, CSS, Javascript, etc. just visit these websites: CSS Examples : Some cascading style
    sheet examples. HTML Tags : Complete HTML tags with attributes and values for XHTML 1.1, also
    known as HTML 4.01. Javascript : JavaScript quick reference. Regular Expressions : Regular
    Expressions for client-side JavaScript quick reference. Characters : HTML Characters (Numeric and
    Alpha),Webdings and Web ASCII codes. Country Codes : Internet Country Codes with phone...
  12. Need Help With Multi-lingual Site Design - (6)
    Does any of you have any ideas on multi-lingual site design? I'm looking for some
    resources/guides that'll show me the exact technique of achieving this... I am NOT looking for
    the Google Translate kind of option, where you've got a bunch of buttons on your site - clicking
    on which, will pass your page through Google Translator producing a totally garbled grammatical
    output in another language... What I want is to define every Text Element on the site as
    variables and depending on the lanugage of your choice, these variables are filled in from
    pre-defin...
  13. How Do You Put Flash Into Your Site? - Help plz... (7)
    Hi, im makin a games site for Tasty Relish Forum. (go here to join and help fill this forum!!!)
    how do I embedd flash games?...
  14. Thinking About An "audio" Web Site - Your feedback please (4)
    Our company is in the web development (and marketing) business. This winter we are re-developing
    our own site, and I have been thinking of making the web site also available as an audio option.
    Since I'm an audio learner this concept interests me, and I figured I would throw this idea to
    you guys for you opinions / feedback etc. as I don't like to act on something without first
    getting feedback from people. I have the right recording gear to make the files sound good, so
    there's no problem there. And I would still do the usual "TEXT" in particular the sea...
  15. Music On My Site? - (18)
    Does enyone know how to add background music to your webpage? Can you do it using html???
    /mellow.gif" style="vertical-align:middle" emoid=":mellow:" border="0" alt="mellow.gif" />
    Notice from microscopic^earthling: Moved to Designing > Web & HTML .
    Absolutely wrong forum. ...
  16. How Do I Keep A Background On My Site - (14)
    I had a background on my site that i got on the internet. I don't remember the name of the site
    but from it I was able to save the background (which was a textured blue background) to
    photobucket.com. I've had it there for awhile, but now, all-of-the-sudden it disappeared. I
    guess you can only keep things on photobucket for so long. But how do I keep a background on my
    site if I can't host it somewhere? Is there a way to put the picture in cPanel and use it from
    there? If there is, I cant figure it out....
  17. Great Online Video Seminar - Declan Dunn (2)
    I just finished watching a truly amazing seminar that was presented by Declan Dunn. We've been
    developing web sites for over a decade and have learned a temendous amount over the years. Many of
    the things that Declan says in this presentation are right in line with my own opinions and
    listening to him speak was very inspiring. He has good examples and tells you "what's what"
    from his experience - not just his opinion. This seminar was part of a conference in Australia that
    attendees paid $3000 to attend. Enjoy! http://video.google.ca/videoplay?docid=-70......
  18. Help Choose A New Banner For Me Please - Help needed to choose a new banner for my site (11)
    Ok yesterday we got busy and spent some time making some new banners for The Sounds Of The Suburbs
    site. We haev can for sort of an urban decay theme on the site..and were going to totally remodel
    it this week to different feel and maybe even get the databases working /wink.gif"
    style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /> So can you take a look at the
    images below and post which one you feel is the best one.. Your views will help us hopefully decide
    on the new banner Banner 1 Banner 2 Banner 3 Banner 4 Banner 5 Banner 6...
  19. With Or Without Tabs? - help me choose design for my site. (15)
    As I run this website for more than a 1 year now, Im getting more and more visitors, I have a
    feeling that navigation on my page isn't such great as it seems on the beggining. I tried to
    navigate like first-time user, and have trouble finding information that I was looking for. So, I
    have an idea, to integrate basic types of information on 4 main TABs at the top of page. Look at
    the two pictures and tell me which one is better: the one with the tabs, or the one without.
    The above picture is new version, with tabs... The above picture is current look ...
  20. How Can You Spice Up Your Basic HTML Site ? Beginner Needs Help - (9)
    Well im new to this,and i know a person who knows how to do HTML,I of course dont lol,but I was
    wondering with html can you change the way the sites you make on here look and ect..(put flash in
    and w/e..)...
  21. To Display Images With Links In A Rotating Sequence Without Refreshing The Page! - how to rotate images with links in a sequence automatically without ha (0)
    hai this is my first post and i really hope someone finds it useful. i was looking for this trick
    for long and finally found out today... to rotate images in your page automatically in a sequence
    without having to refresh the page. i find it particualry useful to highlight on the home page the
    various contents inside my site. Copied from
    http://www.cgiscript.net/cgi-script/csNews...6.5787238091439 QUOTE Step 1: place the code
    below between the and tags within the HTML page where you want the random banners to appear.
    CODE                           ...
  22. Any Ideas About A Free Online Page Editor ? - any ideas? (7)
    I would like to give editing access to some of the staff on my site. However, I do not wish to give
    my staff FTP access, which is the only way I can access one of my sites. I need a free thing that my
    staff will be able to login and edit the HTML of certain pages and of course save teh changes. I do
    have PHP and mySQL enabled on the server. Does anyone know of such an onlin editer? Help would be
    appreciated. Oh, and I think I posted this in the wrong section... my appologies (if I could delete
    this I would)....
  23. Good Site To Download Web Templates ? - (21)
    could anyone recommend a place to download (preferably free (as im not sure i can make it work))
    some (or a) good web template(s), something easy to use and not too complicated! thanks chris p.s
    just needs a couple pages of text (preferably with some graphics which i can change), some contact
    info and links to galleries which i have already made....
  24. Embeding Font Files - How To Embed Fonts To Your Site (1)
    A lot of web designers run into the same problem of wanting a certain font type, but the question
    comes up "How do I guarentee the font to show up without the viewer's computer to install the
    font on the computer?" it's easy, just follow these steps. The first thing you have to do is
    download and install Weft 3 from microsoft, it's free, the download link is on that page. the
    easiest way you can embed a font is by using the wizard and follow the steps commanded to you.
    Easy, but what if you really want to know how the program works, or don't want to...
  25. Free Shoutbox For Your Web-site - And a cool one at that ;) (12)
    Hi guys,     Those who want to avoid the extensive process of setting up a shoutbox on your own
    web-site (messing around with a whole bunch of PHP Code and MySQL Databases in the process) - can
    grab one for FREE rightaway from YellBox. I found out about their site a couple of hours back -
    and it's looks real good. Check out: http://yellbox.com Here's a list of their features:
    QUOTE     *  Instant feedback from visitors you would not hear otherwise.     * Allow your
    visitors to communicate or help each other.     * Greater sense of community will keep vi...
  26. Netscapenav Display Problem << Guru Help Needed - Homepage won't display with Netscape (2)
    Hi all, Heres the latest in the browser display problems. Updated my homepage via ftp. -(deleted the
    old home page in the "www" & "public_html" folders & the ROOT directory "_sgt" & "_sgg"
    folders..before ftp'ing the update). Verrified that all new homepage updates had the correct
    "last modified" date (ie. the server was showing the newest version I just updated in all file
    folders which were previously deleted). Homepage uses HTML with CSS & tables only- no php or
    anything fancy. The only changes I made to the homepage were the addition of some metatags (ie. )
    in ...
  27. Site Designing - (21)
    Do any of you guys have a particular process you go through when designing a site? I always find it
    really hard to get started on a site, and often have to have 4 or 5 gos before I get it right. Is
    there a "perfect formula" out there for getting your designs right every time?...
  28. What Is The Best Language For Web Site ? - What is the best language for web site ? (23)
    Which is the best language, for a web site ? Topic moved, this suits better here, in the
    design/websites forum /wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif"
    /> -- MoonWitch Notice from microscopic^earthling: Moved again.
    Out of Howto's and Tutorials into Designing > Web Design. ...
  29. Get Afree Template For Your Site - (3)
    there is some site whic give u free html templates wich can be so easy to u to design ur own site
    lets share it to find the best i will add the sites i use effex media
    http://www.templatesweb.com/ ...
  30. Web Site Trackers? - (8)
    Hi guys! I need for my site a kind of a tracker, that will show me how many peoples enetred my
    sites, what pages they view, where are they come from? I need detailed information on my visitors!
    is there any such a service for free? plz help!thanks!...



Looking for display, xx, users, online, site

See Also,

*SIMILAR VIDEOS*
Searching Video's for display, xx, users, online, site
Weather Feed
Script In
Php A good
weather feed
on your site
IE6
display:bloc
k hides
other image
BUG
Website
Navigation
Hover
Buttons
Stick So
Made Css
Today need
further help
with
tutorial
from this
site
Find Out
Dead Links
In Your Site
Automaticall
y Want to
see a dead
link on your
site?
Help me I
want to make
site to the
linux
beginer
Redirecting
All Htm
Files To Php
Site...
Flash Pic
Problems
Pics Display
at Low
Resoution
Stretching
My Site
Vertically
Using CSS or
HTML
Unicode
Encoded Site
- Characters
Not
Displaying
Properly?
Cvs For
Maintaining
Your Site
Free Online
Cheatsheets
Need Help
With
Multi-lingua
l Site
Design
How Do You
Put Flash
Into Your
Site? Help
plz...
Thinking
About An
"audio&
quot; Web
Site Your
feedback
please
Music On My
Site?
How Do I
Keep A
Background
On My Site
Great Online
Video
Seminar
Declan Dunn
Help Choose
A New Banner
For Me
Please Help
needed to
choose a new
banner for
my site
With Or
Without
Tabs? help
me choose
design for
my site.
How Can You
Spice Up
Your Basic
HTML Site ?
Beginner
Needs Help
To Display
Images With
Links In A
Rotating
Sequence
Without
Refreshing
The
Page!
how to
rotate
images with
links in a
sequence
automaticall
y without ha
Any Ideas
About A Free
Online Page
Editor ? any
ideas?
Good Site To
Download Web
Templates ?
Embeding
Font Files
How To Embed
Fonts To
Your Site
Free
Shoutbox For
Your
Web-site And
a cool one
at that ;)
Netscapenav
Display
Problem
<<
Guru Help
Needed
Homepage
won't
display with
Netscape
Site
Designing
What Is The
Best
Language For
Web Site ?
What is the
best
language for
web site ?
Get Afree
Template For
Your Site
Web Site
Trackers?
advertisement



How To Display XX Users Online On Your Site ?

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com