Jump to content

User is online or Offline


web_master

Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/125800-user-is-online-or-offline/
Share on other sites

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)?

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?

 

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?

Archived

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

×
×
  • 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.