$admin = $this->M_Base->data_where('admin', 'username', $this->session->get('admin'));
$user_agent = $_SERVER['HTTP_USER_AGENT'];
// Mendeteksi browser
if (preg_match('/Chrome/i', $user_agent)) {
$browser = 'Chrome';
} elseif (preg_match('/Firefox/i', $user_agent)) {
$browser = 'Firefox';
} elseif (preg_match('/Safari/i', $user_agent)) {
$browser = 'Safari';
} elseif (preg_match('/Brave/i', $user_agent)) {
$browser = 'Brave';
} elseif (preg_match('/DuckDuckGo/i', $user_agent)) {
$browser = 'DuckDuckGo';
} elseif (preg_match('/Edg/i', $user_agent)) {
$browser = 'Microsoft Edge';
} elseif (preg_match('/Trident/i', $user_agent)) {
$browser = 'Internet Explorer';
} elseif (preg_match('/Opera/i', $user_agent)) {
$browser = 'Opera';
} elseif (preg_match('/Vivaldi/i', $user_agent)) {
$browser = 'Vivaldi';
} elseif (preg_match('/Yandex/i', $user_agent)) {
$browser = 'Yandex Browser';
} else {
$browser = 'Other';
}
// Mendeteksi Session ID (Jika digunakan)
$session_id = session_id();
// Mendeteksi status permintaan (Kode Status HTTP)
$status_code = http_response_code();
// Mendeteksi alamat IP
$ip_address = $_SERVER['REMOTE_ADDR'];
// start logs admin
$log_file_name = $this->session->get('admin') . '_log_admin_' . date("j.n.Y") . '.txt';
$log_file_path = WRITEPATH . 'logs/' . $log_file_name;
$file = fopen($log_file_path, "a");
$log_data = date('H:i:s d-m-Y') . " | " . "LOGOUT | ID: " . $admin[0]['id'] . " | LAST_LOGOUT: " . date('H:i:s d-m-Y') . " | " . $this->session->get('admin') . " | " . $ip_address . " | " . $user_agent . " | " . $browser . " | " . $session_id . " | " . $status_code . " |\n";
fwrite($file, $log_data);
fclose($file);
// end logs admin