You could write some code that not only creates a session but also inserts the just created session's data into a MySQL table. Then you could use some javscript that deletes the active session from the MySQL when the browser window is closed. After that, it's just a simple matter of counting the number of rows in the MySQL table.
I don't think it's possible with Javascript alone. Maybe AJAX.. But I wouldn't do that.
I would store the user IP plus timestamp in the database and only show the entries that are less than for example 20 minutes old. Do you have a user management system that you want to use, or do you just want to display the IPs?
I don't think it's possible with Javascript alone. Maybe AJAX.. But I wouldn't do that.
I would store the user IP plus timestamp in the database and only show the entries that are less than for example 20 minutes old. Do you have a user management system that you want to use, or do you just want to display the IPs?
Why not use AJAX? Seems like it would be much more accurate, whcih would be significant on high-traffic sites.
I'm not even too sure if that's possible. When you hit the close button the window closes immediatley. I don't think you can prevent the user to close the window when he wants to. AJAX would have to communicate with the server first, which takes some time. Plus this won't work if the user has javascript disabled.
Very few people have javascript disabled. You can check if the user has javascript disabled - if it's disabled, then add a timestamp, if not, the the onUnload event can delete the session from the database. Seems perfectly viable to me.