T
T
tsimur2020-09-30 12:27:40
JavaScript
tsimur, 2020-09-30 12:27:40

How to determine the users who are currently on the site?

How to determine the users who are currently on the site?
And how to keep a list of pages that a specific user has visited for a specific period?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fedor Vlasenko, 2020-09-30
@tsimur

Raise websockets, track onopen, onclose of the user Write
a user poll and poll users by timeout by implementing ping pong (since there are options when there will be no onclose ) There
is no other option active during the last period of time Writing a log of their visits. And more or less accurately, then this is WebSocket

T
ThunderCat, 2020-09-30
@ThunderCat

How to determine the users who are currently on the site?
There are many options, the simplest is the ping method. On the back, create a storage (an array, a file, a database, it doesn’t matter) in which you add the user who came to the site and the entry timestamp. Further, at the front, every N seconds, you request the server for a script that updates the user's timestamp in storage. It is possible to receive in the same place in the answer all active. All. Error in N seconds.
And how to keep a list of pages that a specific user has visited for a specific period?
Logs. It doesn't matter either the file or the database, whichever is more convenient. I went to the page - the time, url, user ID were recorded in the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question