I am trying to make a counter of visitors to the site, I saw it on a variety of resources, but something was not set.
There is a base in which the number of visitors is stored, there is a php script that should add to the base +1 when the user logs in (this works with the ready event) and -1 when it leaves the site (this is the problem). There is a function that sends an ajax request to this php script, and there is an onbeforeunload or unload that calls the function.
I do not know who is the culprit from this list, but the function manages to work even after the page is closed, at its next loading. That is, the function works only when the page is refreshed or restored ( cntrl + shift + T ) even before the ready event, but if the page is simply closed, then there will be no effect at all. Tested only in firefox , because This browser is a priority.
The code itself:
HTML:
<script>window.onunload = putout();</script> Js:
function putout() { $.ajax({ type: "POST", url: "./php/process.php", data: { 'function': 'putout', 'def': def, }, dataType: "json", success: function(data) { }, }); } PHP:
include ('./php/connect.php'); mysql_query("UPDATE numb SET numb=numb-1"); I also heard that the opera ignores these events altogether, then how can you cross-browser implement the site visitors counter at all?
PS The text has already been repaired a thousand times, this is not at all my style of presentation, take note. In general, I hate the possibility of crawling to third-party people without asking for my publications, this is VERY annoying.