// file: logger.php // writes a record to a YY-MM file to record visits // author: Kase // update: 1/3/2019 added getbro date_default_timezone_set('America/Chicago'); $date = date('m/d/Y h:i:s a', time()); $datename = date('y-m', time()); $File = 'logs/'.$datename.".txt"; $debug = 0; // 1=TRUE // ----------------- the below does not need to change $url = @( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] : 'https://'.$_SERVER["SERVER_NAME"]; $url .= ( $_SERVER["SERVER_PORT"] !== 80 ) ? ":".$_SERVER["SERVER_PORT"] : ""; $url .= $_SERVER["REQUEST_URI"]; str_replace(array('http://','https://'), '', $url); str_replace(array('HTTP://','HTTPS://'), '', $url); $ua = strtolower($agent ? $agent : $_SERVER['HTTP_USER_AGENT']); $dvc = 'BOT'; if ((stripos($ua,'android')!==false)) { $dvc = 'Android'; } if ((stripos($ua,'iphone')!==false)) { $dvc = 'iPhone'; } if ((stripos($ua,'ipad')!==false)) { $dvc = 'iPad'; } if ((stripos($ua,'windows nt 5.1')!==false)) { $dvc = 'XP'; } if ((stripos($ua,'windows nt 6.1')!==false)) { $dvc = 'Win7'; } if ((stripos($ua,'windows nt 6.3')!==false)) { $dvc = 'Win8'; } if ((stripos($ua,'windows nt 10')!==false)) { $dvc = 'Win10'; } if ((stripos($ua,'linux x86')!==false)) { $dvc = 'Linux'; } if ((stripos($ua,'macintosh')!==false)) { $dvc = 'Macintosh'; } // ---------------------- get browser data include('getbro.php'); $ua=getBrowser(); $device = $ua['name'].' '.$ua['version'].' '.$ua['platform'].' '.$dvc; if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ipaddress=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { // check ip is pass from proxy $ipaddress=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { // use the basic one $ipaddress=$_SERVER['REMOTE_ADDR']; } // $dumpstr = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=".$_SERVER["REMOTE_ADDR"])); $region = $dumpstr["geoplugin_region"]; $countryName = $dumpstr["geoplugin_countryName"]; $latitude = $dumpstr["geoplugin_latitude"]; $longitude = $dumpstr["geoplugin_longitude"]; $regionName = $dumpstr["geoplugin_regionName"]; $Handle = fopen($File, 'a'); $Data = $date.",". $ipaddress.",". $url.",". $region.",". $regionName.",". $countryName.",". $latitude.",". $longitude.",". $device."\r\n"; fwrite($Handle, $Data); fclose($Handle); // ------------------------------------------- last visitor $myfile = fopen("lastvisit.txt", "w") or die("Unable to write lastvisit"); $txt = $ipaddress.' '.$region.' '.$countryName; fwrite($myfile, $txt); fclose($myfile); if ($debug=='1') { echo $Data; } ?>