NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page Find out how many Visitors Are online

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search
7 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 08-28-2007, 01:34 PM THREAD STARTER               #1 (permalink)
Account Suspended
 
selfpleasured's Avatar
Join Date: Jun 2007
Location: Florida
Posts: 249
selfpleasured is on a distinguished road
 



Thumbs up Find out how many Visitors Are online


very Simple make a page name it whos-online.php, insert this into the page nothing else
????: NamePros.com http://www.namepros.com/code/367496-find-out-how-many-visitors-online.html

PHP Code:
<?php

/*You need php but no database for this as it uses a text file. 
You can add a title, numbers of extra visitors, the refresh time and the text file.
Put this in your root dir. The text file is automatically created for you so you need to load 1 file.
Make sure the text file does not already exist.
You can include this in a page by using <?php include("what_you_named_it .php");?> for html or include("what_you_named_it.php"); for php
*/

/*This is the text you want to explain the number.
Something like;- Visitors on this page or leave blank if the text is going into your document
you need quotes " " and the semicolon ; even if this is empty */
$explain " ";

/* Add online numbers. You can set this to 0 for actual numbers
but rather than visitors feeling lonely you can put a number in to show that nember plus the actuals
so if you put in 4 and have 2 actually on line the counter will show 6 */ 
$additions 0;

/*This is the refresh time in minutes. For example if you use 5 your numbers
refresh every 5 minutes. The lower the number, the more accurate
it is not advisable to make this lower than 1 */ 
$timer 10;

/* Name of the file where all the data will be saved. 
Name this something creative but it must be a text file so xxx.txt. 
make sure this name is not already in the directory. The script creates this file */
$filename "howmanylog1.txt";

//Do not edit under this line

if (!$datei$datei dirname(__FILE__)."/$filename";
$time = @time();
$space " ";
$ip $REMOTE_ADDR;
$string "$ip|$time\n";
$a fopen("$filename""a+");
fputs($a$string);
fclose($a);

$timeout time()-(60*$timer);

$all "";
$i 0;
$datei file($filename);
for (
$num 0$num count($datei); $num++) {
????: NamePros.com http://www.namepros.com/showthread.php?t=367496
$pieces explode("|",$datei[$num]);

if (
$pieces[1] > $timeout) {
$all .= $pieces[0];
$all .= ",";
}
$i++;
}

$all substr($all,0,strlen($all)-1);
$arraypieces explode(",",$all);
$useronline count(array_flip(array_flip($arraypieces)));

// display how many people where activ within $timeout
echo $explain;
echo 
$space;
echo 
$useronline+$additions;


// Delete
$dell "";
for (
$numm 0$numm count($datei); $numm++) {
$tiles explode("|",$datei[$numm]);
if (
$tiles[1] > $timeout) {
$dell .= "$tiles[0]|$tiles[1]";
}
}

if (!
$datei$datei dirname(__FILE__)."/$filename";
$time = @time();
$ip $REMOTE_ADDR;
$string "$dell";
$a fopen("$filename""w+");
fputs($a$string);
fclose($a);
?>
upload to your server at the root add this to your webpage


PHP Code:
<?php
include ("whos-online.php");
?>
this will show you the amount of people online at that time, if you have subdomains off the root and you want to add it to them do so like this:

PHP Code:
<?php
include ("http://www.yourwebsite.com/whos-online.php");
?>
Have fun! if its helpful please say so in my rep Thanks

Added Syntax Highlighting (PHP BBCode) - Hitch
Last edited by Hitch; 08-29-2007 at 08:13 AM.
selfpleasured is offline  
Old 08-29-2007, 08:01 AM   #2 (permalink)
Danltn.com
 
Daniel's Avatar
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute
 


Ethan Allen Fund Ethan Allen Fund
Could you put in [ PHP] [/PHP] tags please... (no space obviously) Makes me much easier to read.

Thanks!

P.S. Include a step saying the file it's writes to must be CHMOD'd so it is writable please .

Edit:
PHP Code:
include ("http://www.yourwebsite.com/whos-online.php"); 
????: NamePros.com http://www.namepros.com/showthread.php?t=367496
at the bottom, would be better if it was
PHP Code:
include ("/home/absolute/path/to/the/directory/whos-online.php"); 
Edit: Please post where you got it from: http://forum.statcounter.com/vb/show...24&postcount=5
Last edited by Danltn; 08-29-2007 at 08:16 AM.
Daniel is offline  
Old 08-29-2007, 08:42 AM THREAD STARTER               #3 (permalink)
Account Suspended
 
selfpleasured's Avatar
Join Date: Jun 2007
Location: Florida
Posts: 249
selfpleasured is on a distinguished road
 



I didnt get it from there. i didnt make it but its not from there a friend gave it to me
selfpleasured is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 07:09 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger