FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


HomeWatched TopicsRegisterSearchDirectory
FAQMemberlistUsergroupsLog inStoresItemsBank
Google

Reply to topic Page 1 of 1
How to track the total number of logged in members
Message  

Reply with quote
Post How to track the total number of logged in members 
I am currently working on a membership based web site. I need to display the number of members

logged in that system.  To do this I have set a flag in the database which is set to 1 whenever a

user is logged in the system and when the user clicks on the ?Log Out? link a query is fired that

sets the same flag to 0.  To display the total number of logged in members I run a query that counts

the number of records whose flag is set to 1.

However this method has a major shortcoming.  When users do not click the ?Log Out? link but just

close the browser.  In such a situation the query that will set the flag field back to 0 will bot be

fired and hence the user would be seen as active in the system even though the user has already left

the system.

When one company is viewing the profile of another company in my site I also need to show whether

that representative of the company whose profile is being viewed in logged in the system at that

time or not so that if the user wants then can send a message to them.

I need some advice on how can I achieve this in the best possible way, where I can display the total

number the total number of correct logged in members

Thanks a lot!

Cheers
Paresh

View user's profile Send private message

Reply with quote
Post  
What you need: PHP Enabled website.
And ftp client.

Save this file as data.php upload it and chomod it in the ftp to 777.

Insert this where you want the online users displayed.
Code:
<?php

$timemax = "300"; //Max. time that users are online on your site (in sec.)

$ipadress = $REMOTE_ADDR;

$timenow = explode (" ", microtime());
$timenow = $timenow[1];

include ("data.php");

$timedelete = $timemax;

$deleted = $deleted + $timedelete;

if ($deleted < $timenow){

$file = fopen("data.php","w+");
fputs($file, "<?PHP \$deleted = \"$timenow\"; ?>\n");

$number = count($visitor_b);

for ($tel = 0; $tel < $number; $tel++){
$visitor_a = $visitor_b[$tel];

$visitor_a[0] = $visitor_a[0] + $timemax;

if ($visitor_a[0] > $timenow)
fputs($file, "<?PHP \$visitor_b[] = array('$visitor_a[0]','$visitor_a[1]'); ?>\n");

}

fclose($file);

}
$visitor_b = "";

include ("data.php");

$number = count($visitor_b);

for ($tel = 0; $tel < $number; $tel++){
$visitor_a = $visitor_b[$tel];

if ($visitor_a[1] == $ipadress)
$save = "nee";

}

if (!$save){

$file = fopen("data.php","a");
fputs($file, "<?PHP \$visitor_b[] = array('$timenow','$ipadress'); ?>\n");
fclose($file);

}

$visitor_b = "";
include ("data.php");

$number = count($visitor_b);

for ($tel = 0; $tel < $number; $tel++){
$visitor_a = $visitor_b[$tel];
$visitor_a[0] = $visitor_a[0] + $timemax;

if ($visitor_a[0] > $timenow)
$online = $online + 1;

}

if (!$online)
$online = 1;

if ($online == 1)
print ("Users Online: $online");
else
print ("Users Online: $online");

?>


View user's profile Send private message
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
  



Google

FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


Web Design by PlatinumShore.com & Web Hosting by TradeWebHosting.com