Whats the easiest way to determine if a user is online? (PHP/MYSQL)

前端 未结 10 1234
轻奢々
轻奢々 2020-12-02 05:24

Is there a way I can piggy back sessions to know if the user is online?

I.e: use logs on, I set a $_SESSION variable, user times out- cookie Garbage collector update

10条回答
  •  再見小時候
    2020-12-02 06:01

    What you are asking for (after the clarification) is, by definition, impossible. HTTP is a connectionless protocol, so as soon as a user has hit a page and all the content comes back from the server to the user's browser, there is no connection between the two. Someone is "online" with your website for less than a second.

    One thing you could do is to have JavaScript on your web page make AJAX requests back to your server on a regular basis which includes identifying information, and a different AJAX request when the user leaves the page, using window.onbeforeunload.

提交回复
热议问题