FORUM HOME | WHUK BLOG   
WEB HOSTING UK AFFORDABLE WEBSITE HOSTING SERVICES IN UNITED KINGDOM
PHP LINUX SHARED HOSTING WINDOWS ASP.NET HOSTING PACKAGES
ECOMMERCE HOSTING ASP MSSQL MS ACCESS ODBC FRONTPAGE HOSTING
CPANEL WHM FANTASTICO RESELLER DEDICATED SERVER WEB HOSTING
CHEAP PLESK CPANEL HTML MYSQL BEST UK VPS HOSTING COMPANY
CHEAP RELIABLE UK HOSTING PROVIDER SINCE 2001
MANAGED WEB HOSTING SERVICE
AFFORDABLE WEBSITE HOSTING SERVICES IN UNITED KINGDOM

Web Hosting UK Forums | Linux Windows Dedicated Server and cPanel VPS Hosting Forum » Web Hosting and Domains » FAQ's / Tutorials.

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 24-01-09, 06:39 PM
Junior Member
 
Join Date: Jan 2009
Posts: 22
Default Free php snippet to display users online

<?php

$file_name = "whois_online.dat.php";
$c_time = time();
$timeout = 300;
$time = $c_time - $timeout;
$ip = getenv("REMOTE_ADDR");

if(!file_exists($file_name)){
$fp = fopen($file_name, "w");
fwrite($fp, "<?php die('Restricted File');?> \n");
fclose($fp);
}


$fp = fopen($file_name, "a");
$write = $ip."||".$c_time."\n";
fwrite($fp, $write);
fclose($fp);


$file_array = file($file_name);
$online_array = array();
for($x = 1; $x < count($file_array); $x++){
list($ip, $ip_time) = explode("||", $file_array[$x]);
if($ip_time >= $time){
array_push($online_array, $ip);
}
}

$online = array_unique($online_array);
$online = count($online);
if($online == "1"){
print "User online: $online"."<br>";
}else{
print "Users online: $online"."<br>";
}
?>
Reply With Quote

  #2 (permalink)  
Old 26-01-09, 10:25 AM
Sales Team
 
Join Date: Sep 2006
Posts: 1,628
Send a message via MSN to Harry Send a message via Skype™ to Harry
Default

Thank you Abhas for sharing your resource
I am not much into Web development and programming but after going through your code i think using this code we can get number of online users who are surfing our website, Right ?
If 'Yes' where should i put above code [ which directory ] so that i can get/show current traffic details for my website.
__________________
UK VPS Hosting || Managed Server Hosting || Reseller Hosting
Looking for extra revenue ?
Join our webhosting affiliate program and earn upto £300 Webhosting UK Affiliate
Reply With Quote

  #3 (permalink)  
Old 27-01-09, 11:20 PM
Junior Member
 
Join Date: Jan 2009
Location: root@127.0.0.1 [~]# cd /etc/pwd
Posts: 12
Send a message via MSN to XXxxImmortalxxXX
Default

Hello Harry your question regarding where should i put that?

By default all forums have a who is onlie page

for example your online page would be

Code:
http://www.webhosting.uk.com/forums/online.php
If your wanting to know if you could put that on your main website you could but also think of the vulnerabilities as well

this script displays ips

Code:
$ip = getenv("REMOTE_ADDR");
i would rather use http script than the getenv one

you will be taking a risk of helping malicious users gain viewable and live computers ips

which is a major security risk


but the file here would be called

Code:
if(!file_exists($file_name))
where file_name = what you want it to be

i do hope this helps if im wrong im very sorry
Reply With Quote

  #4 (permalink)  
Old 28-01-09, 06:58 AM
Sales Team
 
Join Date: Sep 2006
Posts: 1,628
Send a message via MSN to Harry Send a message via Skype™ to Harry
Default

Thank you for clear explanation I really appreciate it.
__________________
UK VPS Hosting || Managed Server Hosting || Reseller Hosting
Looking for extra revenue ?
Join our webhosting affiliate program and earn upto £300 Webhosting UK Affiliate
Reply With Quote

  #5 (permalink)  
Old 28-01-09, 02:41 PM
Junior Member
 
Join Date: Jan 2009
Location: root@127.0.0.1 [~]# cd /etc/pwd
Posts: 12
Send a message via MSN to XXxxImmortalxxXX
Default

not a problem at all glad to help you
Reply With Quote

  #6 (permalink)  
Old 04-07-09, 09:55 PM
Junior Member
 
Join Date: Jul 2009
Posts: 20
Default

thanks for this tuto

it's really nice
Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT. The time now is 03:37 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Copyright 2001-2010 Web Hosting UK. All rights reserved.
Web Hosting UK Forum





Site Map

Shared Cloud
Shared Cloud From £1

Affiliate Program
Earn up to £300 Per Sale

Dedicated Servers
Dedicated Server Hosting

Cloud Hosting
Cloud Server Hosting

Load Balanced Server
Load Balancing Server

VPS Hosting
Linux VPS Hosting

Windows VPS
Windows 2003 VPS

Zimbra Hosting
Zimbra Email Hosting

cPanel Hosting
Shared Linux Hosting

Windows Hosting
Shared Windows Hosting

Coldfusion Hosting
Windows Coldfusion Hosting

cPanel Reseller Hosting
Shared Windows Hosting

Windows Reseller
Windows Reseller Hosting

Email Web Hosting
Email Hosting

Semi-Dedicated Server
Semi-Dedicated Hosting

Remote Backup Plans
Offsite Backup Service


cpanel hosting
Knowledgebase Articles

Pre-Sales Question
Web Hosting FAQ's

Dedicated Hosting
Dedicated Server FAQ's

Virtual Private Servers
VPS Hosting

PHP MySQL Hosting
cPanel Hosting

Windows Hosting
ASP MSSQL Hosting

Domain Name
Domain registration FAQ's

CMS Hosting
CMS Hosting FAQ's

Payment Gateways
Payment FAQ's


Support Tutorials

cPanel Tutorials
cPanel Flash Tutorials

Wordpress Tutorials
Wordpress Flash Tutorials

Plesk Tutorials
Plesk Flash Tutorials

PhpMyadmin Tutorials
PhpMyadmin Flash Tutorials

Drupal Tutorials
Drupal Flash Tutorials

Mambo Tutorials
Mambo Flash Tutorials

Joomla Tutorials
Joomla Flash Tutorials

More Hosting Tutorials