Questions about determining whether a user is online !!!

Source: Internet
Author: User
Questions about determining whether a user is online !!! I have been hearing about how to determine whether a user is online. I have no idea. I 'd like to ask you for help today !! Thank you !!


Reply to discussion (solution)

Record the session to the database, and mark the user's ID number. to determine whether the user is online, check whether the session information corresponding to the ID number has expired. I don't know if I'm right. thank you for making a brick downstairs.

Let's take a look at the session usage.

It mainly determines the final activity time and sets a short default online time. if there is no activity record within this time period, it is considered offline; on the contrary, it is considered online.

I did not make it clear. first, when a user clicks out through a normal channel, it is unnecessary to say that the user is online or offline. I want to ask how to know whether the user is online when the browser is closed without clicking exit.

Let's talk about your opinion. O (∩ _ ∩) O thank you.

Record the session to the database, and mark the user's ID number. to determine whether the user is online, check whether the session information corresponding to the ID number has expired. I don't know if I'm right. thank you for making a brick downstairs.

Please refer to below for additional information

Let's take a look at the session usage.

Please refer to below for additional information

Isn't it the same? how to save it.

Isn't it the same? how to save it.

The key is time settings.

1. Why do we need to determine whether a user is online?
Since the user is not online, he will not send a request to you.
Unless you have a need to display online users
2. when can I determine whether a user is online?
When you need to display the number of online users, at least one user sends a request.
Only count the number of online users in response to this request.
If no one visits your website, what is the purpose even if the statistics are collected?
3. how to determine whether a user is online?
No matter whether a user is registered or not, you only need to count the number of valid sessions.
If you think the default session expiration period of 1440 seconds is too long, you can adjust it as needed

So how do you determine whether a user has activities? ? Isn't this request added to every page...

This logic is like this, not a request, because every page of you must determine whether the user is online? Each page reads the session information, which is updated during the read.

You may need to know your online friends, but it also requires a period of time.

1. ajax sets a time period to be sent to the server, proving that it is online. if the time limit is exceeded, it is not

2. set a time period when the user does not access the page, sends a request, disconnects the session, and knows that the page is not online.

In short, it is impossible to know whether the user is online in real time. a reasonable period of time is required.

This depends on how you record the login information. if it is just a simple session, you only need to determine whether the session corresponding to the user information exists or expires. Other ideas are similar, it is always a question about whether it is valid!

After reading the replies, I learned a little about it, but I still didn't figure it out. This is because I want to determine whether the user is online, and then exit automatically when the user is offline.

Then, let's take a look at the ideas for such a statement ??


So how do you determine whether a user has activities? ? Isn't this request added to every page...

This logic is like this, not a request, because every page of you must determine whether the user is online? Each page reads the session information, which is updated during the read.

Downstairs

You may need to know your online friends, but it also requires a period of time.

1. ajax sets a time period to be sent to the server, proving that it is online. if the time limit is exceeded, it is not

2. set a time period when the user does not access the page, sends a request, disconnects the session, and knows that the page is not online.

In short, it is impossible to know whether the user is online in real time. a reasonable period of time is required.

For ajax asynchronous requests, do you need to add the code to each page?

Set the time period to see if the user accesses the page. how can this problem be implemented? Unexpectedly ....

Next, let's look at what I said. thank you.

Record last user access time
Check the interval between the last access time and the current time. if the access time exceeds the specified range, the access time is deemed to be offline.

The work to determine whether User A is online is carried out during user B's activities
It is determined to be performed independently on the server and has nothing to do with the client.

You can use a memory table to update the user's last operation time, and then use Cron to regularly clean up the user, so that the table is the most recent online user.

We can also close the browser event!

I think the first floor is very detailed.

After reading the replies, I thought a little bit about it. let's look back at the results. thank you for your understanding of O (∩ _ ∩) O ha! The time is tight and there is no time to reply to you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.