Jump to content

Archived

This topic is now archived and is closed to further replies.

raza.shahzad

Showing the list of online users when programming an online chat room...........

Recommended Posts

I started to work out an online chat room using PHP. the basic idea was to use PHP wity MySQl to provide the users with a good online web browser based chat experience. In doing so i caught myself up in a problem that i want to discuss with you guys.
Displaying the list of online users is not a big issue with PHP. The 'behind the scene' structure is like....
1. the user logs in to the website with his username and password. everything is as simple as it can be. and there can be many other ways for doing so. i will appreciate help in any direction.
2. the database contains a column that saves the status of the user say:
name=status
value=online or offline.
if the user is online the status is set to the same and for offline the status in the database is saved or changed/updated to offline.
as long as the user uses the website/chat his name appears to be online and as he/she clicks log off, his status is set back to offline. and so on.
the problem comes when the user disconnects without clicking the log off link. in this case i am unable to set the database entry of status to offline because the user leaves the chat, turns off his browser or shuts down his PC without clicking the log off button due to which the process remains incomplete and other users who are online see the person to be online too.
Simply speaking, i want to know a better way to implement to my chat website. i wish the solution be like yahoo or msn messengers. whenever a user logs off or shuts down his PC accidently, the other user recieves a message that MR.XYZ has logged off.
Is there any solution to this problem. definitely there are many. the one i am thinking of is to place a field in the database that stores the time the last msg was recieved from the user and if the time extends a particular period, say 15minutes, the script considers the user to be offline. but this one is not the same as i want it to be like yahoo messengers'.

Share this post


Link to post
Share on other sites
This is a problem many chatrooms have. One solution might be to open the chatroom in a new browser window, and detect when the window is closed with javascript, which can call a php script to log the user out.

Share this post


Link to post
Share on other sites
[quote author=raza.shahzad link=topic=101857.msg403538#msg403538 date=1153872169]
I started to work out an online chat room using PHP. the basic idea was to use PHP wity MySQl to provide the users with a good online web browser based chat experience. In doing so i caught myself up in a problem that i want to discuss with you guys.
Displaying the list of online users is not a big issue with PHP. The 'behind the scene' structure is like....
1. the user logs in to the website with his username and password. everything is as simple as it can be. and there can be many other ways for doing so. i will appreciate help in any direction.
2. the database contains a column that saves the status of the user say:
name=status
value=online or offline.
if the user is online the status is set to the same and for offline the status in the database is saved or changed/updated to offline.
as long as the user uses the website/chat his name appears to be online and as he/she clicks log off, his status is set back to offline. and so on.
the problem comes when the user disconnects without clicking the log off link. in this case i am unable to set the database entry of status to offline because the user leaves the chat, turns off his browser or shuts down his PC without clicking the log off button due to which the process remains incomplete and other users who are online see the person to be online too.
Simply speaking, i want to know a better way to implement to my chat website. i wish the solution be like yahoo or msn messengers. whenever a user logs off or shuts down his PC accidently, the other user recieves a message that MR.XYZ has logged off.
Is there any solution to this problem. definitely there are many. the one i am thinking of is to place a field in the database that stores the time the last msg was recieved from the user and if the time extends a particular period, say 15minutes, the script considers the user to be offline. but this one is not the same as i want it to be like yahoo messengers'.
[/quote]

Share this post


Link to post
Share on other sites

×

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.