<?php
#error_reporting(E_ALL);
#ini_set('display_errors', 1);
#echo __LINE__."<br>";

function agent($ulid)
{

  $db = dbconnect();
  $result = $db->query("SELECT ip, user_agent, isp, organisation, host 
                          FROM prog_userlog_admin
                         WHERE ulid=$ulid");
  $row = $result->fetch_array();

  // Land ermitteln
  #$country_name = apache_note("GEOIP_COUNTRY_NAME");
  // IP Adresse ermitteln
  $ip_addr = $row['ip'];
  #$ip_addr = getenv('REMOTE_ADDR');
  #$portnum = getenv('REMOTE_PORT');

  //Betriebssystem ermitteln
  $agent=$row['user_agent'];
  #$agent=$_SERVER['HTTP_USER_AGENT'];
  $os   ="Unbekannt";

  if   (strstr($agent, "Windows 98"))      $os="Windows 98";
  elseif (strstr($agent, "NT 4.0"))        $os="Windows NT ";
  elseif (strstr($agent, "Android"))       $os="Android";
  elseif (strstr($agent, "NT 5.1"))        $os="Windows XP";
  elseif (strstr($agent, "NT 6.0"))        $os="Windows Vista";
  elseif (strstr($agent, "NT 6.1"))        $os="Windows 7";
  elseif (strstr($agent, "NT 6.2"))        $os="Windows 8";
  elseif (strstr($agent, "NT 6.3"))        $os="Windows 8.1";
  elseif (strstr($agent, "NT 10.0"))       $os="Windows 10.0";
  elseif (strstr($agent, "Mac"))           $os="Mac OS";
  elseif (strstr($agent, "Linux"))         $os="Linux";
  elseif (strstr($agent, "Unix"))          $os="Unix";

  //Browser ermitteln

  // Firefox
  if (strpos($agent, "Firefox") || strpos($agent, "Firebird")) {
  $version = $row['user_agent'];$version = explode("/",$version);$version = $version[3];
  $browser = "Firefox $version";
  }

  // Internet Explorer
  if (strpos($agent, "MSIE")) {
  $version = $row['user_agent'];$version = explode(";",$version);$version = $version[1]; // MSIE X.X
  $version = $version = explode(" ",$version);$version = $version[2];  // X.X
   $browser = "Internet Explorer $version";
  }
  if (strpos($agent, "Camino")) {
  $browser = "Camino";
  }
  if (strpos($agent, "Galeon")) {
  $browser = "Galeon";
  }
  if (strpos($agent, "Konqueror")) {
  $browser = "Konqueror";
  }
  if (strpos($agent, "Safari")) {
  $browser = "Safari";
  }
  if (strpos($agent, "OmniWeb")) {
  $browser = "OmniWeb";
  }	
  if (strpos($agent, "Opera")) {
    $browser = "Opera";
  }
  if (preg_match('/Trident\/[0-9\.]+/', $agent) && preg_match('/rv:([0-9\.]+)/', $agent, $match)) {
    $browser = "Internet Explorer $match[1]";
  }
  if (strpos($agent, "Presto")){
  $version = $row['user_agent'];$version = explode("/",$version);$version = $version[3];
  $browser = "Opera $version";
  }
  
  if (!isset($browser)) {
  $browser = "Unbekannt";
  }
  return "$ip_addr|$browser|$os|$row[isp]|$row[organisation]|$row[host]";
}
?>