I created simple hit counter that sends ajax requests to determine how long visitor is viewing the page.
In JS im just hitting PHP file every few seconds:
var ajaxreq = new XMLHttpRequest();
ajaxreq.open("GET", "visitlogger.php", true);
ajaxreq.send();
PHP file (visitlogger.php) stores data in MySQL database. - stores "first hit timestamp" - stores HTTP_REFERER, user agent, IP etc. - updates "last hit timestamp" if session ID exists (to check how long user had page opened)
Now I need some cookie or something, to group visits by unique visitors.
How to do it?