62 lines
2.7 KiB
PHP
Executable File
62 lines
2.7 KiB
PHP
Executable File
<?php
|
|
|
|
// -----------------------------------------------------
|
|
// init
|
|
// -----------------------------------------------------
|
|
// if (empty($includePath)) { $includePath="../_include"; }
|
|
//include ($includePath ."/dataBaseConnect.php");
|
|
|
|
$resConn='';
|
|
$nbConnect='0';
|
|
|
|
// -----------------------------------------------------
|
|
// Recherche des dejà connectés
|
|
// -----------------------------------------------------
|
|
$reqSelect = "SELECT count(ip) as `nb` from `cpt_connectes` WHERE ip='" .$_SERVER['REMOTE_ADDR']. "' ;";
|
|
if (isset($debug[16]) && $debug[16] == '1' ) $debugMsg .= monDebug(2,['reqSelect' => $reqSelect],'online.php');
|
|
$resConn=$idPdo->query($reqSelect);
|
|
if ($resConn) {
|
|
$res=$resConn->fetch(PDO::FETCH_ASSOC);
|
|
$nbConnect=$res['nb'];
|
|
if (isset($debug[2]) && $debug[2] == '1' )
|
|
{ $admMsg .= '<br><span class="msgOk">resultat connexion en cours ip = ' .$nbConnect. '</span>'; $admMsgClass='ok';}
|
|
}
|
|
|
|
// -----------------------------------------------------
|
|
// Maintien ou ajout de la connection
|
|
// -----------------------------------------------------
|
|
if ($nbConnect!=0) {
|
|
if (isset($_SERVER['REMOTE_ADDR'])) $reqUpdate = "UPDATE `cpt_connectes` SET timestamp='".time(). "' WHERE ip='" .$_SERVER['REMOTE_ADDR']. "' ;";
|
|
if (isset($debug[16]) && $debug[16] == '1' ) $debugMsg .= monDebug(2,['reqUpdate' => $reqUpdate],'');
|
|
$resConn=$idPdo->query($reqUpdate);
|
|
}
|
|
|
|
// -----------------------------------------------------
|
|
// Creation de la connection
|
|
// -----------------------------------------------------
|
|
if ($nbConnect==0 || empty($nbConnect) ) {
|
|
$reqInsert = "INSERT into `cpt_connectes` (ip, timestamp) values ('" .$_SERVER['REMOTE_ADDR']. "', '".time(). "') ;";
|
|
$resConn=$idPdo->query($reqInsert);
|
|
if (isset($debug[16]) && $debug[16] == '1' ) $debugMsg .= monDebug(2,['reqUpdate' => $reqUpdate],'');
|
|
}
|
|
|
|
// -----------------------------------------------------
|
|
// Delete la connection + de 5 minutes
|
|
// -----------------------------------------------------
|
|
$times_m_5mins = time()-(50); //en secondes
|
|
$reqDelete = "delete from `cpt_connectes` WHERE timestamp < '" .$times_m_5mins. "' ;";
|
|
$resConn=$idPdo->query($reqDelete);
|
|
if (isset($debug[16]) && $debug[16] == '1' ) $debugMsg .= monDebug(2,['reqDelete' => $reqDelete],'');
|
|
|
|
// -----------------------------------------------------
|
|
// Nombre de connectés final
|
|
// -----------------------------------------------------
|
|
$reqSelect="SELECT count(ip) as `nb2` from `cpt_connectes`;";
|
|
$resConn='';
|
|
$resConn=$idPdo->query($reqSelect);
|
|
if ($resConn) {
|
|
$res1=$resConn->fetch(PDO::FETCH_ASSOC);
|
|
$nbConnect2=$res1['nb2'];
|
|
if (isset($debug[16]) && $debug[16] == '1' ) $debugMsg .= monDebug(2,['Il y a actuellement' => $nbConnect2],'');
|
|
}
|
|
?>
|