Burak Çalışkan

PHP access_log mysql aktarma

  • 6 sene önce, Burak Çalışkan tarafından yazılmıştır.
  • PHP access_log mysql aktarma için yorumlar kapalı
  • PHP

connect_error) {
die(“Baglanti Hatasi: ” . $conn->connect_error);
}

$handle = fopen(“/var/log/nginx/access.log”, “r”);
$satirs = “”;
$ipadresi = “”;
if ($handle) {
while (($line = fgets($handle)) !== false) {
// process the line read.
//$satirs = $line;
$ipadresi = explode(” – – “, $line);
$ipadresi = trim($ipadresi[0]);
if($ipadresi !== “85.96.184.61”){
$sql = “INSERT INTO access_log (satir,ip,zaman) VALUES (‘$line’,’$ipadresi’,now());”;
$conn->query($sql);
}
}
//print_r($satirs);
fclose($handle);
} else {
// error opening the file.
}

$conn->close();
?>