Location: PHPKode > scripts > Visitor Logger > logger.php
<?php

session_start();

if (file_exists($VL_include_path."/config.txt")) {

	include($VL_include_path."/config.txt");

	$VL_conn = @mysql_connect($VL_server, $VL_username, $VL_password);

	if ($VL_conn) {

		$VL_dbcon = @mysql_select_db($VL_dbname, $VL_conn);

		if ($VL_dbcon) {


			$VL_ip = $_SERVER['REMOTE_ADDR'];
			if (!$VL_ip) $VL_ip = "Unknown";
			else {
				$VL_host = gethostbyaddr($VL_ip);

				if (!$_SESSION['VL_flag']) {

					$VL_ip_split = explode(".",$VL_ip);
					$VL_ip_decimal = (16777216*$VL_ip_split[0]) + (65536*$VL_ip_split[1]) + (256*$VL_ip_split[2]) + $VL_ip_split[3];

					if (($VL_ip_decimal >= 16777216) AND ($VL_ip_decimal <= 1410024191)) $VL_database = "/databases/ip-country-1.csv";
					elseif (($VL_ip_decimal >= 1410024192) AND ($VL_ip_decimal <= 3229359359)) $VL_database = "/databases/ip-country-2.csv";
					elseif (($VL_ip_decimal >= 3229359872) AND ($VL_ip_decimal <= 3275922943)) $VL_database = "/databases/ip-country-3.csv";
					elseif (($VL_ip_decimal >= 3275922944) AND ($VL_ip_decimal <= 3420061695)) $VL_database = "/databases/ip-country-4.csv";
					elseif (($VL_ip_decimal >= 3420061696) AND ($VL_ip_decimal <= 4294967295)) $VL_database = "/databases/ip-country-5.csv";

					if ($VL_database) {
			
						$VL_read_csv = fopen($VL_include_path.$VL_database,"r");

						while ($VL_line = fgetcsv($VL_read_csv)) {

							if (($VL_ip_decimal >= $VL_line['0']) AND ($VL_ip_decimal <= $VL_line['1'])) {
								$VL_path = "flags/".$VL_line['3'].".gif";
								$_SESSION['VL_flag'] = "<img src=\"".$VL_path."\" alt=\"".$VL_line['2']."\" title=\"".$VL_line['2']."\" />";
								break;
							}

						}
						fclose($VL_read_csv);
					}
				}

			}

			if (!$VL_host) $VL_host = "Unknown";
			if (!VL_country) $VL_country = "Unknown";
			if (!$VL_flag) $VL_flag = "----";

			$VL_page = $_SERVER['SCRIPT_NAME'];
			if ($VL_page == "/index.php") $VL_page = "home";
			else {
				$VL_page=str_ireplace("/index.php", "", $VL_page);
				$VL_page=substr($VL_page,1);
			}

			@include($VL_include_path."/mobile.txt");
			if (!$VL_browser) @include($VL_include_path."/browser.txt");
			if (!$VL_browser) $VL_browser = "Unknown";

			$VL_referer=$_SERVER['HTTP_REFERER'];
			$VL_referer=str_ireplace("http://www.", "", $VL_referer);
			$VL_referer=str_ireplace("http://", "", $VL_referer);
			$VL_referer=str_ireplace("https://www.", "", $VL_referer);
			$VL_referer=str_ireplace("https://", "", $VL_referer);
			if (stristr($VL_referer, "google")) {
				$VL_pos = strpos($VL_referer,"?");
				if ($VL_pos !== false) $VL_google_1 = substr($VL_referer,0,$VL_pos);
				if ($VL_pos !== false) $VL_google_2 = substr($VL_referer,$VL_pos);
				$VL_pos = strpos($VL_google_2,"&q=");
				if ($VL_pos !== false) $VL_google_2 = substr($VL_google_2,$VL_pos+3);
				$VL_pos = strpos($VL_google_2,"&");
				if ($VL_pos !== false) $VL_google_2 = substr($VL_google_2,0,$VL_pos);
				$VL_google_2=str_ireplace("%20", "+", $VL_google_2);
				$VL_referer = $VL_google_1." ".$VL_google_2;
			}
			if (stristr($VL_referer, "yahoo")) {
				$VL_pos = strpos($VL_referer,"/search");
				if ($VL_pos !== false) $VL_yahoo_1 = substr($VL_referer,0,$VL_pos);
				if ($VL_pos !== false) $VL_yahoo_2 = substr($VL_referer,$VL_pos);
				$VL_pos = strpos($VL_yahoo_2,"&p=");
				if ($VL_pos !== false) $VL_yahoo_2 = substr($VL_yahoo_2,$VL_pos+3);
				$VL_pos = strpos($VL_yahoo_2,"&");
				if ($VL_pos !== false) $VL_yahoo_2 = substr($VL_yahoo_2,0,$VL_pos);
				$VL_yahoo_2=str_ireplace("%20", "+", $VL_yahoo_2);
				$VL_referer = $VL_yahoo_1." ".$VL_yahoo_2;
			}
			$VL_referer = substr($VL_referer,0,100);
			if (!$VL_referer) $VL_referer = "None";

			$VL_language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
			if (!$VL_language) $VL_language = "-----";

			$VL_today = getdate();
			$VL_time = $VL_today['hours'].":".$VL_today['minutes'].":".$VL_today['seconds'];
			$VL_day = $VL_today['year']."-".$VL_today['mon']."-".$VL_today['mday'];

			$VL_str = "insert into $VL_table values ('','".$VL_ip."','".$VL_host."','".$VL_page."','".$VL_browser."','".$_SESSION['VL_flag']."','".$VL_referer."','".$VL_language."','".$VL_time."','".$VL_day."')";

			@mysql_query($VL_str,$VL_conn);
		}
	}
}

?>
Return current item: Visitor Logger