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?
What I would do is save two cookies, first which will have small expiration and other as long say 4-6months, if the second cookie is set you know he ain't a unique visitor, but still drawbacks are:
1) if cookies disabled?
2)if cookies are cleared?
Edit code: