Jump to content

Recommended Posts

  • Hi all
     
    I'm writing a little chat application so my users can contact an expert via an IM system.  I'm pretty much through the planning stage and have most of the code worked out (in my head!!) as to how I can do this.  However, the one bit I can't get my head around is how to write to a DB table if a user closes their browser instead of logging out. 
     
    I've very little Javascript knowledge (my way of saying none!!) and would like some kind person to talk me through in laymans terms how to set this up.
     
    The process I would like to happen is

  1. user logs in and php changes field in DB table to show user/expert is online
  2. user has chat session
  3. user logs out (or closes browser) and php changes field in DB table to show user/expert offline

 

The other reason for this being written to a DB table is in the future it will be developed to show when users/experts are busy and involved in discussions.

 

Any help you guys can offer would be greatly appreciated.

 

It's also been suggested that I use Temporary Tables.  Can anyone give me a quick overview of these and how they would function.  Would both users need to log out/close browsers to delete the tables or just one?

Link to comment
https://forums.phpfreaks.com/topic/231374-write-to-db-when-closing-browser/
Share on other sites

Use jQuery's unload handler.

http://api.jquery.com/unload/

 

Make an AJAX call to a script that writes to your database. If you have no JS knowledge then I would really recommend looking at jQuery. Start off with a few beginner videos on YouTube. Take a look at the use of AJAX with jQuery also.

 

http://docs.jquery.com/Tutorials

Hi,

I tried a similar approach but heard that unload is unreliable, so I am planning to make an ajax call to the system every 1 minute to update the last activity of the user. (This sure would make increase the size of the table when more users come in)

Do you think this is the right way to do?  Please advice if there is a better way of doing this.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.