Hello friends,

I am doing one project in which i need to find currently online users.how can i ? is there any way ?

another thing , if i fetch user login history in DB table and check from there if user currently login or not then there will be one problem occur like if user close browser without logout then his/her status will remains logged in as per DB table's entry.(because his session will set)

So for this , Is there any way to find user's last activity with web page ? so i can logout him/her after some predefined time.

Thanks in advance

Hello friends,

I am doing one project in which i need to find currently online users.how can i ? is there any way ?

another thing , if i fetch user login history in DB table and check from there if user currently login or not then there will be one problem occur like if user close browser without logout then his/her status will remains logged in as per DB table's entry.(because his session will set)

So for this , Is there any way to find user's last activity with web page ? so i can logout him/her after some predefined time.

Thanks in advance

<? 
      session_start();
       // set timeout period in seconds
     $inactive = 10;
      // check to see if $_SESSION['timeout'] is set
      if(isset($_SESSION['timeout']) ) 
	  {
      $session_life = time() - $_SESSION['timeout'];
 
      if($session_life > $inactive)

      {
/*write here update user status query*/ 
	   session_destroy(); header("Location: logout.php"); 
	   }
 
      }
       if(isset($_SESSION['user_no']) && $_SESSION['user_no']!='')
	   {
      $_SESSION['timeout'] = time();
	  
	  }
	  ?>

this code shows that if user idle for 10mini it will logout .

Yes , i found that.

Anyways thanks for help ....

Yes , i found that.

Anyways thanks for help ....

Well then u should mark the thread as solved..:)

Hello friends,

I am doing one project in which i need to find currently online users.how can i ? is there any way ?

another thing , if i fetch user login history in DB table and check from there if user currently login or not then there will be one problem occur like if user close browser without logout then his/her status will remains logged in as per DB table's entry.(because his session will set)

So for this , Is there any way to find user's last activity with web page ? so i can logout him/her after some predefined time.

Thanks in advance

use status in database '0' for offline and 1 for online. when ever user login that status update '0' to '1'. before logout write update qery for status '1' to '0'.
and finally fetch status=1 where you want who is online.

use status in database '0' for offline and 1 for online. when ever user login that status update '0' to '1'. before logout write update qery for status '1' to '0'.
and finally fetch status=1 where you want who is online.

well i guess he mentioned this problem in his first post itself that when a user closes the browser window, his status still remains logged in according to the DB which he doesnt wants...
The right approach is to find inactive time through sessions and log the user out automatically after a specific time..
Cheers!!

well i guess he mentioned this problem in his first post itself that when a user closes the browser window, his status still remains logged in according to the DB which he doesnt wants...
The right approach is to find inactive time through sessions and log the user out automatically after a specific time..
Cheers!!

ok. fine. i i saw raja's reply. it will works fine. but i send this reply for other users . anything wrong in my reply?

ok. fine. i i saw raja's reply. it will works fine. but i send this reply for other users . anything wrong in my reply?

I wont say there s anything wrong in ur idea as ur method can be used to keep track of time when user last logged in but as far as finding if a user is ol or not, this would fail...
n btw why would anyone go for this when they have a better solution on the same thread..
just my views... no offense intended..

surely just saving the login timestamp updating it every time the page is refreshed and then querying for users where the timestamp is less than x minutes ago are online would be the best answer?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.