Check if user closed the page in PHP?

前端 未结 9 1986
孤城傲影
孤城傲影 2020-12-22 06:04

I made a chat using PHP and JavaScript chat and there is a disconnect button which removes user from the chat removing him from user list first. But if the user closes brows

9条回答
  •  执笔经年
    2020-12-22 06:42

    If you can't modify the JS code for some reason, there really is little you can do. Only thing you can do with PHP is to check if there's been for example over 15 minutes from the last activity, the user has left. But this is in no way a smart thing to do – a user might just sit and watch the conversation for 15 minutes.

    Only proper way to do is using AJAX polling in set intervals if you want to do it reliably.

    You noted that a user polls the server for new messages constantly, can't you use that to detect if user has left?

提交回复
热议问题