frustrating problem with php and javascript

playminigames

New Member
Messages
216
Reaction score
6
Points
0
Ok so on my site you can see friends that are online, so why you log out they go offline, but when you close out the browser they log out, but they dont go "Offline". so i tried a little ajax with it for unload to send a request to the page to logout, but it logs out every time you change the page, so it doesnt work. Any help with this would be great.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
One option would be to keep a count of open pages on the server. Add onload and onunload handlers that request pages to increment and decrement the count. When the count is 0 for 1 minute or more, the user's status is "offline" but is still considered logged in.

Another option is to have pages make keepalive requests every minute or so. These requests can set other status information, such as "away" when the user hasn't interacted with the page for more than a given amount of time. If a user is logged in but a keepalive request hasn't come in for a given period, change the user's status to "offline".

Note that the former will be tricky to implement properly and the latter is inefficient.
 
Last edited:

playminigames

New Member
Messages
216
Reaction score
6
Points
0
thanks, i was thinking about the second option, but i wasnt quite sure, thanks for the input!
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
What does knowing that a friend is online get someone? What can they do with that knowledge? Can they interact with the friend in any way?
 

playminigames

New Member
Messages
216
Reaction score
6
Points
0
im hoping to make a chat system, but that will be way later, as im not that good at javascript yet
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
One thing to look into is Comet. You could layer a chat app onto it and it can provide a way of telling whether someone is online or offline, though the different Comet techniques have their own impact on resource usage.
 

playminigames

New Member
Messages
216
Reaction score
6
Points
0
yes, i thats what i was thinking, but it doesnt need to be done now. Thanks for all the help
 

garikr

New Member
Messages
46
Reaction score
0
Points
0
This is a bit off topic, just letting you know... this is what I get when I tried to register on your site(www.playminigames.co.cc)

Warning: Missing argument 4 for MySQLDB::addNewUser(), called in /home/pmg/public_html/include/session.php on line 645 and defined in /home/pmg/public_html/database.php on line 158

Warning: Missing argument 5 for MySQLDB::addNewUser(), called in /home/pmg/public_html/include/session.php on line 645 and defined in /home/pmg/public_html/database.php on line 158

Warning: Cannot modify header information - headers already sent by (output started at /home/pmg/public_html/database.php:158) in /home/pmg/public_html/process.php on line 213

Hope this will help with your testing
 

playminigames

New Member
Messages
216
Reaction score
6
Points
0
ahhh yes, if you try again you will notice that this is fixed, i had two extra variables that i didnt need, but the variables were empty so it would throw that error. Thanks for that anyways
 
Top