<?php
if (isset($user)) {

$who_lastusers="30"; // не советую много писать
$ip=$_SERVER['REMOTE_ADDR'];

$u1=getenv('HTTP_USER_AGENT');
$brow=strtok($u1,'/');

$ip=htmlspecialchars(stripslashes($ip));
$brow=htmlspecialchars(stripslashes($brow));



$lines=file("L2dbnam/esql2db/who.dat");
$count=count($lines);
for ($b=0; $b<$count; $b++) { list($sinbase)=explode("|",$lines[$b]); if ( $user == "$sinbase") { $del=$b;

$fp=fopen("L2dbnam/esql2db/who.dat","w");
flock ($fp,LOCK_EX);
unset($lines[$del]);
fputs($fp, implode("",$lines));
flock ($fp,LOCK_UN);
fclose($fp);} }
$time=time();

$self = $_SERVER['SCRIPT_NAME'];


$ttt="$user|$self|$time";

$fp = @fopen("L2dbnam/esql2db/who.dat","a+");
flock ($fp,LOCK_EX);
@fputs($fp,"$ttt\r\n");
fflush ($fp);
flock ($fp,LOCK_UN);
@fclose($fp);

$file=file("L2dbnam/esql2db/who.dat"); $i = count($file);
if ($i>=$who_lastusers) {
$fp=fopen("L2dbnam/esql2db/who.dat","w");
flock ($fp,LOCK_EX);
unset($file[0]);
fputs($fp, implode("",$file));
flock ($fp,LOCK_UN);
fclose($fp);}}else{exit ;}
?>
