-8

Offline and online user in admin page. I want to show users online in admin page in php using session? I don't have idea to proceed.

halfer
  • 19,824
  • 17
  • 99
  • 186
v g
  • 1
  • 1
  • You should set flag in your DB table. If user is authenticated successful then set it to 1 and on logout set it to 0. By counting 1 you can get your online users. – Ravi Hirani Feb 01 '16 at 10:56
  • @RaviHirani I disagree. That would be quite unreliable. What if the user doesn't logout? What if the browser is closed unexpectedly and therefor can't be caught by js? Personally I think that if you want a reliable way to check who's online, use something like a websocket. – icecub Feb 01 '16 at 10:59
  • use database session and include add one column (Active_user) if its true then it means user is online else offline. – Monty Feb 01 '16 at 11:04

2 Answers2

2

The best way to do is, put a key named 'is_online' inside your database. Now when a user login, update this key as 1. On the other hand when the user clicks log out, update the key to 0. By default set it to 0. Now you can fetch all the users having is_online = 1 and is_online = 0.

This is the overview of procedure, now its up to you how you code this.

Helping link : Detect online users?

Community
  • 1
  • 1
Maha Dev
  • 3,915
  • 2
  • 31
  • 50
1

You need to add a column in your DB to set if the user is online. For example the column online and set 1 when user log in and 0 when log out.

After in your admin page, you just need to select user WHERE online = 1

Berserk
  • 821
  • 12
  • 23