I have made a chat box like thing in PHP. The only problem is that it doesn’t automatically reload. Is there a way to make it reload in PHP, or would I have to move everything around so I can use AJAX? Also, one of my users is constantly online. I have set it to be that they are offline if they have pressed a key or clicked in the last 3 minutes and to set them offline when they leave the page. They are using Firefox 9.0. Is this because of the use of onunload? What would be a solution?
Share
You could use a
meta refreshtag, that could be generated by PHP, but its not really a PHP-specific feature.This will refresh the content after 600 seconds. You could throttle that time more accurately based on your applications demands.
Ajax is probably the preferred method for checking user inactivity. Here is a similar post on checking user activity – How can I detect with JavaScript/jQuery if the user is currently active on the page?
UPDATE
As for the second question of how to handle exit of a user in Firefox, its like you said that
onunloadcan be inconsistent. This is where the use of ajax shines again. If your app stops receiving ajax updates from the client, you can do some sort of cleanup to mark them as inactive.We had a similar situation in an ASP.Net MVC app. We ended up using Application Variables to store recent activity and state of users. A php example can be found here.
Hope this helps!