Create a file called log.js
or something like this and put it in the "root" of the public folder ( public_html
or www
, depends on your system)
Then create a file called log.php
also in root
Now in log.js
add this:
note: (new Date().getTime())
is only to avoid caching
(function (d) {
function trigger() {
var oReq = new XMLHttpRequest();
//Defina como true
oReq.open("GET", "/log.php?_=" + (new Date().getTime()), true);
//Envia a requisição, mas a resposta fica sendo aguardada em Background
oReq.send(null);
}
//Verifica se a página já foi carregada
if (/^(interactive|complete)$/i.test(d.readyState)) {
trigger();
} else {
d.addEventListener('DOMContentLoaded', trigger);
}
})(document);
No log.php
add to your mysql statements:
<?php
//Conecta
$mysqli = new mysqli("localhost", "usuario", "senha", "banco");
if (mysqli_connect_errno()) {
printf("Erro de conexão: %s\n", mysqli_connect_error());
exit;
}
$ip = $_SERVER['REMOTE_ADDR'];
$result = $mysqli->query('INSERT INTO 'logs' ('data', 'ip') VALUES (now(), \'' . $ip . '\')');
if ($result) {
$result->close();
}
$mysqli->close();
Now on all HTML pages add
<script src="/log.js"></script>