Guys, tell me how to bring into the admin panel who is now online on the site authorized users + need to be displayed on the page where the name of the user is online or offline. Can anyone share a script with the instruction?

You also need a function that will create the desired column in the database, because there I don’t understand anything at all. Or maybe it can be tied to id_akk?

photo base

  • The structure shown does not allow to know when an authorized user has performed the last action - therefore, it is impossible to guess whether it is online or not, due to the absence of initial data. - Akina
  • what else do you need tell me i'll post it? - Luba
  • Need a log structure action. - Akina
  • added new photo - Luba

2 answers 2

It is necessary to create the last_activity column in the user table with the data type storing the date, for example, timestamp , and change the value to NOW() in any user action.

After that, you can determine who is online using this column.

For example, you can consider online people with last_activity-time()<5 .

  • can you help realize this? - Luba

It is best to do this in some kind of in-memory key-value storage (Memcached, Redis) with the possibility of data aging.

For each authorized user action or authorization (not to be confused with authentication), update the value in the cache, for example.
When deauthenticating, delete the value.

When needed, get a list of live values.

Redis example:

 SET users_online_42 42 60 ; set user#42 online for next 60 sec DEL users_online_42 ; set user#42 offline KEYS users_online_* ; список ΠΊΠ»ΡŽΡ‡Π΅ΠΉ для ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΉ ΠΎΠ½Π»Π°ΠΉΠ½, ΠΌΠΎΠΆΠ½ΠΎ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½Ρ‹ΠΉ id ΠΊΠ°ΠΊ подстроку ΠΈΠ»ΠΈ Ρ‡Π΅Ρ€Π΅Π· GET key