Accountant of Visits

To add an accountant of visits HTML to its webpage


As to add an accountant of visits HTML to your webpage, the accountant more advanced to take complete statistics of the accesses to your webpage. With this accountant of visits you can collect all the data related to the user who visits your Web: IP of the visitor, length, latitude, city, postal code, hour of connection and time in each page that happens.


index.php <! <title>Contador DOCTYPE html> <html> <head> of visitas</title> </head> <body>/* If <input exists the sessi³n of user to add user_id to associate visit to this user * type= " hidden€ you go = " to sessionuser€ VALUE = "" > <h1>Contador! </h1> </body> <script src =€/code.jquery.com/jquery.min.js " ></script> <script src = " accountant-of-visitas.js " ></script> </html>



accountant-of-visitas.js

bar u='contador.php'; $.ajax (\ {type: €œPOST€, URL: or, it dates: \ {key: document.domain, Web: window.location.href, user: $ (€˜to #sessionuser€™) .val ()}}); $ (window) .bind (€˜beforeunload€™, function () \ {$.ajax (\ {type: €œPOST€, URL: or, it dates: \ {key: document.domain, Web: window.location.href, type: 1}})}); myVar=setInterval bar (function () \ {to myTimer ()}, 60000); function to myTimer () \ {$.ajax (\ {type: €œPOST€, URL: or, it dates: \ {key: document.domain, Web: window.location.href, user: $ (€˜to #sessionuser€™) .val (), type: 2}})}



contador.php

<? php
  //Connection MYSQL $host_db = €œlocalhost€; mysql_connect (€˜localhost€™, €˜user€™, €˜password€™); mysql_select_db (€˜basededatos€™); mysql_query (€œSET YAMS €˜utf8€™€); //FUNCTIONS function get_real_ip () \ {if (isset ($_SERVER [€œHTTP_CLIENT_IP€]))\ {return $_SERVER [€œHTTP_CLIENT_IP€]; } elseif (isset ($_SERVER [€œHTTP_X_FORWARDED_FOR€]))\ {return $_SERVER [€œHTTP_X_FORWARDED_FOR€]; } elseif (isset ($_SERVER [€œHTTP_X_FORWARDED€]))\ {return $_SERVER [€œHTTP_X_FORWARDED€]; } elseif (isset ($_SERVER [€œHTTP_FORWARDED_FOR€]))\ {return $_SERVER [€œHTTP_FORWARDED_FOR€]; } elseif (isset ($_SERVER [€œHTTP_FORWARDED€]))\ {return $_SERVER [€œHTTP_FORWARDED€]; } else \ {return $_SERVER [€œREMOTE_ADDR€]; }} function obtenerdominio ($dominio) \ {$dominio = trim ($dominio); $dominio = str_replace (Array (€œhttp://€, €œwww. €), €œ, $dominio); $dominio = explode (€œ/€œ, $dominio); $dominio = $dominio [0]; return $dominio; } function obtenerpagina ($dominio) \ {$dominio = explode (€œ/€, $dominio); return end ($dominio); } //AIM FUNCTIONS $ipadress = get_real_ip (); $hostname = gethostbyaddr ($ipadress); $useragent = $_SERVER [€˜HTTP_USER_AGENT€™]; $keyweb = $_POST [€˜key€™]; $web = obtenerdominio ($_POST [€˜Web€™]); $pagina = obtenerpagina ($_POST [€˜Web€™]); €˜usuary€™ $usuario = $_POST []; $type = intval ($_POST [€˜type€™]); /*0 entrance, 1 salida*/if ($keyweb==$web) \ {$str_datos = file_get_contents (€œhttp://api.ipinfodb.com/v3/ip-city/?key=45abd2951ee0a74973b579544185c02820ca02a4a692f615786a68d9e7e8903a&ip=€. $ipadress. €œ&format=json€); $datos = json_decode ($str_datos, true); $ciudad = $datos [€œcityName€]; $pais = $datos [€œcountryName€]; $cp = $datos [€œzipCode€]; $latitud = $datos [€œlatitude€]; $longitud = $datos [€œlongitude€]; $time = $datos [€œtimeZone€]; if (empty ($type))\ {$reg = mysql_query (€œINSERT INTO accountant (IP, host, navigator, city, country, cp, latitude, length, tricks out of, date, user, Web, paginates, type) VALUEs (€˜$ipadress€™, €˜$hostname€™, €˜$useragent€™, €˜$ciudad€™, €˜$pais€™, €˜$cp€™, €˜$latitud€™, €˜$longitud€™, €˜$time€™, NOW (), €˜$usuario€™, €˜$web€™, €˜$pagina€™, €˜0€™)€) or die (mysql_error ()); } else \ {$reg = mysql_query (€œINSERT INTO accountant (IP, host, navigator, city, country, cp, latitude, length, tricks out of, date, user, Web, paginates, type) VALUEs (€˜$ipadress€™, €˜$hostname€™, €˜$useragent€™, €˜$ciudad€™, €˜$pais€™, €˜$cp€™, €˜$latitud€™, €˜$longitud€™, €˜$time€™, NOW (), €˜$usuario€™, €˜$web€™, €˜$pagina€™, €˜$type€™)€) or die (mysql_error ()); }}
}



mysql.sql

  DROPS TABLE IF EXISTS €˜accountant €˜; €˜Accountant €˜CREATES TABLE to YOU (€˜you go €˜int (11) unsigned NOT NULL AUTO_INCREMENT, €˜IP €˜to varchar (20) DEFAULT NULL, €˜host €˜to varchar (50) DEFAULT NULL, €˜navigator €˜to varchar (250) DEFAULT NULL, €˜city €˜to varchar (50) DEFAULT NULL, €˜country €˜to varchar (20) DEFAULT NULL, €˜cp €˜to varchar (6) DEFAULT NULL, €˜latitude €˜to varchar (15) DEFAULT NULL, €˜length €˜to varchar (15) DEFAULT NULL, €˜tricks out of €˜to varchar (9) DEFAULT NULL, €˜date €˜datetime NOT NULL, €˜user €˜int (11) NOT NULL, €˜Web €˜to varchar (100) DEFAULT NULL, €˜paginate €˜to varchar (100) DEFAULT NULL, €˜type €˜int (2) NOT NULL, PRIMARY KEY (€˜you go €˜)) ENGINE=MyISAM CHARSET=utf8 DEFAULT;