<?php
function conectare($place,$plclink='')
{
global$conn,$de,$page;
if($page>1&&$plclink!='')
$plclink.=(mb_substr_count($plclink,'?')>0?'&amp;page='.$page:'/pagina/'.$page);
if($page>1)
$place.=' - pagina '.$page;
if($de==0)
{
if(!$conn->query('INSERT INTO`vizitatori`SET`ip`="'.$_SERVER['REMOTE_ADDR'].'",`browser`="'.($_SERVER['HTTP_USER_AGENT']??'').'",`data`="'.$_SERVER['REQUEST_TIME'].'",`actiune`="'.$place.'",`link`="/'.$plclink.'"'));
$conn->query('UPDATE`vizitatori`SET`data`="'.$_SERVER['REQUEST_TIME'].'",`actiune`="'.$place.'",`link`="/'.$plclink.'"WHERE`ip`="'.$_SERVER['REMOTE_ADDR'].'"&&`browser`="'.($_SERVER['HTTP_USER_AGENT']??'').'"');
$conn->query('DELETE FROM`vizitatori`WHERE`data`<'.($_SERVER['REQUEST_TIME']-3600));
}
$conn->query('UPDATE`membrii`SET`activitate`="'.$_SERVER['REQUEST_TIME'].'"WHERE`id`="'.$de.'"&&`vizibil`="0"');
if(!$conn->query('INSERT INTO`membrii_conectati`SET`de`="'.$de.'",`data`="'.$_SERVER['REQUEST_TIME'].'",`loc`="'.$place.'",`link`="/'.$plclink.'"'))
$conn->query('UPDATE`membrii_conectati`SET`data`="'.$_SERVER['REQUEST_TIME'].'",`loc`="'.$place.'",`link`="/'.$plclink.'"WHERE`de`="'.$de.'"');
$conectati=$conn->query('SELECT COUNT(*)FROM`membrii_conectati`')->fetch_row()[0];
if($conectati>=$conn->query('SELECT`valoare`FROM`setari`WHERE`id`="2"')->fetch_row()[0])
$conn->query('UPDATE`setari`SET`nume`="'.$_SERVER['REQUEST_TIME'].'",`valoare`="'.$conectati.'"WHERE`id`="2"');
$maxtoday=$conn->query('SELECT`ppl`FROM`maxim_conectati`WHERE`ddt`="'.date('d-m-Y').'"')->fetch_row()[0];
if($maxtoday==0||$maxtoday=='')
{
$conn->query('INSERT INTO`maxim_conectati`SET`ddt`="'.date('d-m-Y').'",`ppl`="1",`dtm`="'.date('H:i:s').'"');
$maxtoday=1;
}
if($conectati>=$maxtoday)
$conn->query('UPDATE`maxim_conectati`SET`ppl`="'.$conectati.'",`dtm`="'.date('H:i:s').'"WHERE`ddt`="'.date('d-m-Y').'"');
}