5/5 (1 avis)
Snippet vu 11 648 fois - Téléchargée 20 fois
/* EXEMPLE */ ob_start("ob_gzhandler"); ... YMA_LogVisit('%Host-%Y-%m.log','./logs/',200); ob_end_flush(); /* SOURCE */ function YMA_LogVisit($logFileName='%Host-%Y-%m.log',$logsFolder='./logs/',$responseHTTP='200') { $now = time(); $output = ''; $loggedData['IP'] = trim($_SERVER['REMOTE_ADDR']); $remoteAddr = gethostbyaddr($loggedData['IP']); // Parfois, il y a des caractères spéciaux, notamment NUL $remoteAddr = trim($remoteAddr,"\x00..\x1F"); if (strlen($remoteAddr) > 120) { // Présence probable de caractères NUL $loggedData['REMOTE_ADDR'] = $loggedData['IP']; } else { $loggedData['REMOTE_ADDR'] = $remoteAddr; } $output .= $loggedData['REMOTE_ADDR']; $loggedData['HTTP_HOST'] = strtolower($_SERVER['HTTP_HOST']); if ($loggedData['HTTP_HOST'] == '') $loggedData['HTTP_HOST'] = strtolower($_SERVER["SERVER_NAME"]); $output .= ' '.$loggedData['HTTP_HOST']; $loggedData['TIMESTAMP'] = $now; // Decalage horaire en seconde $decalage = date('Z',$now); // En heures et minutes $decheure = abs(ceil($decalage / 3600)); $decminute = abs(ceil(abs($decalage) / 60)-($decheure * 60)); // En heures avec 2 décimales, et signé $decalagehoraire = sprintf('%02d',$decheure).sprintf('%02d',$decminute); if ($decalage >= 0) { $decalagehoraire = '+'.$decalagehoraire; } else { $decalagehoraire = '-'.$decalagehoraire; } $output .= ' - ['.gmdate('d/M/Y:H:i:s',$now).' '.$decalagehoraire.']'; $loggedData['REQUEST_METHOD'] = $_SERVER['REQUEST_METHOD']; $loggedData['REQUEST_URI'] = $_SERVER['REQUEST_URI']; $loggedData['SERVER_PROTOCOL'] = $_SERVER['SERVER_PROTOCOL']; $output .= ' "'.$loggedData['REQUEST_METHOD'].' '.$loggedData['REQUEST_URI'].' '.$loggedData['SERVER_PROTOCOL'].'"'; $output .= ' '.$responseHTTP; if (ob_get_length() !== FALSE) { $loggedData['CONTENT_LENGTH'] = ob_get_length(); $output .= ' '.$loggedData['CONTENT_LENGTH']; } else { $output .= ' -'; } $loggedData['HTTP_REFERER'] = $_SERVER['HTTP_REFERER']; if ($loggedData['HTTP_REFERER'] != '') { $output .= ' "'.$loggedData['HTTP_REFERER'].'"'; } else { $output .= ' "-"'; } $loggedData['HTTP_USER_AGENT'] = $_SERVER['HTTP_USER_AGENT']; $output .= ' "'.$loggedData['HTTP_USER_AGENT'].'"'; $output = trim($output)."\r\n"; $loggedData['logFileName'] = strftime(str_replace('%Host',$loggedData['HTTP_HOST'],$logFileName),$now); $logPath = $logsFolder.$loggedData['logFileName']; if ($f = @fopen($logPath, 'ab')) { fwrite ($f, $output, strlen($output)); fclose($f); } return $loggedData; }
26 nov. 2008 à 14:37
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.