Online users help

Started on the old forum in April 2011 · view the original in the archive · old links redirect here

6 replies · 564 views · started 15 years ago · 1 min read

3 participants
poporopop25 Developer · 60 posts #1

Please help... this code only display online users who are browsing on the same directory,... i need to display all users who are browsing in all directory...

<?php
$data="online1.dat";
//print date('his A',time()-((10*60*60)+(30*60)));
$time=time()-((10*60*60)+(30*60));
$past_time=$time-1200;
$readdata=@fopen($data,"r") or die("? ? ? ? $data");
$data_array=file($data);
@fclose($readdata);
if (getenv('HTTP_X_FORWARDED_FOR'))
$user = getenv('HTTP_X_FORWARDED_FOR');
else
$user = getenv('REMOTE_ADDR');
$page = getenv('REQUEST_URI');
$agent = getenv('HTTP_USER_AGENT');
$d=count($data_array);
for($i=0;$i<$d;$i++)
{
list($live_agent,$live_user,$live_page,$last_time)=explode("::","$data_array[$i]");
if($live_user!=""&&$last_time!=""&&$live_agent!=""&&$live_page!=""):
if($last_time<$past_time):
$live_user="";
$last_time="";
$live_agent="";
endif;
if($live_user!=""&&$last_time!=""&&$live_agent!="")
{
if($user==$live_user&&$agent==$live_agent)
{
$online_array[]="$agent::$user::$page::$time\r\n";
}
else
$online_array[]="$live_agent::$live_user::$live_page::$last_time";
}
endif;
}
if(isset($online_array)):
foreach($online_array as $i=>$str)
{
if($str=="$agent::$user::$page::$time\r\n")
{
$ok=$i;
break;
}
}
foreach($online_array as $j=>$str)
{
if($ok==$j) { $online_array[$ok]="$agent::$user::$page::$time\r\n"; break;}
}
endif;
$writedata=@fopen($data,"w") or die("? ? ? ? $data");
@flock($writedata,2);
if($online_array=="") $online_array[]="$agent::$user::$page::$time\r\n";
foreach($online_array as $str)
fputs($writedata,"$str");
@flock($writedata,3);
@fclose($writedata);
$readdata=@fopen($data,"r") or die("? ? ? ? $data");
$data_array=@file($data);
@fclose($readdata);
$online=count($data_array);
print "<a href='who.php' class='index'>Online:" .$online."</a>";
?>
something else Fellow · 2,296 posts #2

something like this:

<?php 
$cwd = getcwd();
chdir('Your Folder Name');
$data="online1.dat"; 
//print date('his A',time()-((10*60*60)+(30*60))); 
$time=time()-((10*60*60)+(30*60)); 
$past_time=$time-1200; 
$readdata=@fopen($data,"r") or die("? ? ? ? $data"); 
$data_array=file($data); 
@fclose($readdata); 
if (getenv('HTTP_X_FORWARDED_FOR')) 
$user = getenv('HTTP_X_FORWARDED_FOR'); 
else 
$user = getenv('REMOTE_ADDR'); 
$page = getenv('REQUEST_URI'); 
$agent = getenv('HTTP_USER_AGENT'); 
$d=count($data_array); 
for($i=0;$i<$d;$i++) 
{ 
list($live_agent,$live_user,$live_page,$last_time)=explode("::","$data_array[$i]"); 
if($live_user!=""&&$last_time!=""&&$live_agent!=""&&$live_page!=""): 
if($last_time<$past_time): 
$live_user=""; 
$last_time=""; 
$live_agent=""; 
endif; 
if($live_user!=""&&$last_time!=""&&$live_agent!="") 
{ 
if($user==$live_user&&$agent==$live_agent) 
{ 
$online_array[]="$agent::$user::$page::$time\r\n"; 
} 
else 
$online_array[]="$live_agent::$live_user::$live_page::$last_time"; 
} 
endif; 
} 
if(isset($online_array)): 
foreach($online_array as $i=>$str) 
{ 
if($str=="$agent::$user::$page::$time\r\n") 
{ 
$ok=$i; 
break; 
} 
} 
foreach($online_array as $j=>$str) 
{ 
if($ok==$j) { $online_array[$ok]="$agent::$user::$page::$time\r\n"; break;} 
} 
endif; 
$writedata=@fopen($data,"w") or die("? ? ? ? $data"); 
@flock($writedata,2); 
if($online_array=="") $online_array[]="$agent::$user::$page::$time\r\n"; 
foreach($online_array as $str) 
fputs($writedata,"$str"); 
@flock($writedata,3); 
@fclose($writedata); 
$readdata=@fopen($data,"r") or die("? ? ? ? $data"); 
$data_array=@file($data); 
@fclose($readdata); 
$online=count($data_array); 
print "<a href='who.php' class='index'>Online:" .$online."</a>";
chdir($cwd); 
?>
poporopop25 Developer · 60 posts #3

something else wrote: something like this:

<?php 
$cwd = getcwd();
chdir('Your Folder Name');
$data="online1.dat"; 
//print date('his A',time()-((10*60*60)+(30*60))); 
$time=time()-((10*60*60)+(30*60)); 
$past_time=$time-1200; 
$readdata=@fopen($data,"r") or die("? ? ? ? $data"); 
$data_array=file($data); 
@fclose($readdata); 
if (getenv('HTTP_X_FORWARDED_FOR')) 
$user = getenv('HTTP_X_FORWARDED_FOR'); 
else 
$user = getenv('REMOTE_ADDR'); 
$page = getenv('REQUEST_URI'); 
$agent = getenv('HTTP_USER_AGENT'); 
$d=count($data_array); 
for($i=0;$i<$d;$i++) 
{ 
list($live_agent,$live_user,$live_page,$last_time)=explode("::","$data_array[$i]"); 
if($live_user!=""&&$last_time!=""&&$live_agent!=""&&$live_page!=""): 
if($last_time<$past_time): 
$live_user=""; 
$last_time=""; 
$live_agent=""; 
endif; 
if($live_user!=""&&$last_time!=""&&$live_agent!="") 
{ 
if($user==$live_user&&$agent==$live_agent) 
{ 
$online_array[]="$agent::$user::$page::$time\r\n"; 
} 
else 
$online_array[]="$live_agent::$live_user::$live_page::$last_time"; 
} 
endif; 
} 
if(isset($online_array)): 
foreach($online_array as $i=>$str) 
{ 
if($str=="$agent::$user::$page::$time\r\n") 
{ 
$ok=$i; 
break; 
} 
} 
foreach($online_array as $j=>$str) 
{ 
if($ok==$j) { $online_array[$ok]="$agent::$user::$page::$time\r\n"; break;} 
} 
endif; 
$writedata=@fopen($data,"w") or die("? ? ? ? $data"); 
@flock($writedata,2); 
if($online_array=="") $online_array[]="$agent::$user::$page::$time\r\n"; 
foreach($online_array as $str) 
fputs($writedata,"$str"); 
@flock($writedata,3); 
@fclose($writedata); 
$readdata=@fopen($data,"r") or die("? ? ? ? $data"); 
$data_array=@file($data); 
@fclose($readdata); 
$online=count($data_array); 
print "<a href='who.php' class='index'>Online:" .$online."</a>";
chdir($cwd); 
?>

something wrong in this code... it only display the users online on specific folder not the whole...

something else Fellow · 2,296 posts #4

it set up so your whole site runs off of one folder .... so it doesnt have to open hundreds of directories to see if someone is online... all you have to do is replace this script with every original script on server but change the line: chdir('Your Folder Name'); so it works off of one folder .... so could be:

chdir('./data/'); // root folder to folder called data

or

chdir('../data/'); // secondary folder .. back to root folder .. and to folder called data.

chdir('../../data/'); //3rd folder to 2nd folder to root folder to data folder

wapmetal Lead · 609 posts #6

add that function to online.php and add to your pages

<? include "online.php"; ?>

and just edit online1.dat

by adding "../"

sample

$online = "../online1.dat"; wherein online1.dat is located from a folder so that , it will be the same storage of the data

.

poporopop25 wrote: do i have to put online1.dat in every folder??

the author should add just 1 online1.dat

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close