web_master Posted September 25, 2008 Share Posted September 25, 2008 hi, I want to notify on page if somebody is online or offline. At first I made the table of users which contain: users_id, users_nick, users_password, ... users_online_session, users_online_datetime As second here is a login page where is generate 3 cookies: 1. cookie of nick 2. cookie of password 3. session cookie ********************************** 1. session_register("myusername"); session_register("mypassword"); Name: PHPSESSID Value: 8817198435... etc Host: www.domain.com Path: / Secure: No Expires: At End Of Session ********************************** 2. setcookie("nick", $myusername, NULL, "/", "www.domin.com"); setcookie("pass", $mypassword, NULL, "/", "www.domin.com"); Name: nick Value: username Host: .www.domain.com Path: / Secure: No Expires: At End Of Session Name: pass Value: blablabla Host: www.domain.com Path: / Secure: No Expires: At End Of Session ******************************** So, when somebody log in I can put this informations (PHPSESSID, log in datetime) into dBase. How can I print on page that is somebody Online in this moment? Mean, I can read the data from dBase with iframe, a refresh the datas from dBase ... And how can I know that is somebody close his browser and not online anymore? Quote Link to comment https://forums.phpfreaks.com/topic/125800-user-is-online-or-offline/ Share on other sites More sharing options...
web_master Posted September 26, 2008 Author Share Posted September 26, 2008 Is anybody can help me? --- just tell me what else php-script I need to put here (if I have it) to help me... thnxs Quote Link to comment https://forums.phpfreaks.com/topic/125800-user-is-online-or-offline/#findComment-651248 Share on other sites More sharing options...
Maq Posted September 26, 2008 Share Posted September 26, 2008 Just have a field in your table called, "is_logged_on" and set it to 1 or 0 depending if the user is logged on. So for example when the user logs on set it to 1 and as soon as his session ends or he logs off then set it to 0. Quote Link to comment https://forums.phpfreaks.com/topic/125800-user-is-online-or-offline/#findComment-651249 Share on other sites More sharing options...
web_master Posted September 26, 2008 Author Share Posted September 26, 2008 Just have a field in your table called, "is_logged_on" and set it to 1 or 0 depending if the user is logged on. So for example when the user logs on set it to 1 and as soon as his session ends or he logs off then set it to 0. well, this is the problem, how can I do this? when the user is log in into login_success page I do this: <?php // USER $query_return = mysql_query("SELECT * FROM `r90_users` WHERE `r90_users_nick` = '".$_COOKIE['nick']."' AND `r90_users_password` ='".$_COOKIE['pass']."'"); if(!$query_return) { print mysql_error(); exit; } $request = mysql_fetch_array($query_return); $query_return = mysql_query( "UPDATE `r90_users` SET `r90_users_onlinedate` = '".date("Y-m-d H:i:s")."', `r90_users_onlineip` = '".getenv("REMOTE_ADDR")."' WHERE `r90_users_id` = '".$request['r90_users_id']."' "); ?> that mean that I register users logged in date-time and his IP. So I will add the "logon_logoff" field, but I dont know how can I put login into dbase (1), and the biggest problem is how can I change it to logoff (0)? Quote Link to comment https://forums.phpfreaks.com/topic/125800-user-is-online-or-offline/#findComment-651256 Share on other sites More sharing options...
Maq Posted September 26, 2008 Share Posted September 26, 2008 When the user logs on: $query_return = mysql_query( "UPDATE `r90_users` SET `r90_logged_in` = 1"); $query_return = mysql_query( "UPDATE `r90_users` SET `r90_logged_in` = 0"); Then when you check to see if the user is logged in just do grab the field 'r90_logged_in' and if it's 1 they're logged in, if 0 then they aren't. Is this what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/125800-user-is-online-or-offline/#findComment-651262 Share on other sites More sharing options...
web_master Posted September 26, 2008 Author Share Posted September 26, 2008 Yes, this is what I want... but - when somebody log in I can put the "1" into "r90_logged_in" field. But, lots of users (99% ) just close the browser window without pushing log-off link, in this case I cannot change the "r90_logged_in" into value "0". Is some solution for this probelm? Quote Link to comment https://forums.phpfreaks.com/topic/125800-user-is-online-or-offline/#findComment-651267 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.