Is it possible to check if the visitor is still online using their IP Address?
I have already created a javascript and php to check the visitors ip address when they open one of my page using onLoad and onBeforeUnload event. But there are some cases that my script cannot detect if the visitor is still opening my site. Since onBeforeUnload is not reliable all the time.
In this case, I want to know if there are some other method to detect if the visitor is still online.
If the visitor still open the page but don’t read it because may be he/she is reading other site or running other program I would still consider he/she is online.
If the visitor however, closed the browser but my script fail to detect its unload event I want to know if he/she still online.
A PHP or javascript is okay for me.
You should create JavaScript code that “pings” (sends a request, could be blank) the server via ajax. This request should in turn “mark” that user active in PHP (maybe in a database, or whatever storage method you use). You can refer to that storage of yours to see if the user is online.
Alternatively, you can use it without AJAX, however you need to do this “ping” every page request (everytime you traverse pages) in the site. In this manner, PHP “marks” the user for every page visited as long as he’s logged in.
If that user was “marked” active for more than a certain threshold (like say 30 mins), consider him offline.
you DON’T need an IP address for this functionality. You just need to know that the user is still being marked as online.