如何检测访问我网站的人的行为?

问题描述:

我在这个网站上看到,你可以发现这个人是在线还是离线,或者他是否在线,他在哪个页面上?我怎么能为我的网站做到这一点?

I have seen in this site that you can find out wether the person is online or offline or if he is online on which page he is ? How can I do that for my site ?


我在这个网站上看到你可以找到你的网站这个人是在线还是离线,或者如果他在哪个页面上在线?我怎样才能为我的网站做到这一点?
I have seen in this site that you can find out wether the person is online or offline or if he is online on which page he is ? How can I do that for my site ?



我不知道这个网站,但如果你不得不做这样的事情。

  • 做一张桌子,说 current_activities ,在包含三个字段的数据库中, user_id 状态 last_activity
  • I don''t know about this site, but if you have to do something like this.

    • Make a table, say current_activities, in the database with three fields, user_id, status and last_activity.
      • 当用户登录到您的站点时,请更新状态字段。
      • 每次用户访问页面时,您可能是做一个cookie验证的事情。当您这样做时,请更新 last_activity 字段。
      • 当用户退出您的网站时,请关闭状态 flag。
      • And when a user logs out of your site, turn off the status flag.



      我不知道这个网站,但是你必须做这样的事情。
      • 在数据库中创建一个表格,例如 current_activities ,其中包含三个字段, user_id 状态 last_activity
      I don''t know about this site, but if you have to do something like this.
      • Make a table, say current_activities, in the database with three fields, user_id, status and last_activity.
      • 当用户登录您的站点时,请更新状态字段。
      • 每次用户访问某个页面时,您可能正在进行Cookie验证。当您这样做时,请更新 last_activity 字段。
      • 当用户退出您的网站时,请关闭状态 flag。
      • And when a user logs out of your site, turn off the status flag.



      这是一个很好的逻辑,而且我会如何实现它。


      但是如果用户没有注销,只是存在浏览器?


      你很聪明地采取用户上次活动的时间,以及何时显示一个显示所述用户上次活动的页面,使用当前时间检查数据库中的时间,如果它大于1小时,则声明用户离线并更新状态相应地。

      That''s good logic, and exactrly how i''d go about it.

      But what if the user doesn''t log out and just exists the browser?

      You''d be smart to take the time of the users last activity, and when showing a page which shows said users last activity, check this time in your database with the current time, and if it is greater than, say, 1hour, declare the user offline and update the status accordingly.



      这是一个很好的逻辑,而且我会如何去做它。


      但如果用户没有注销并且只是存在浏览器怎么办?


      你很聪明地采取用户上次活动的时间,当显示显示所述用户上次活动的页面时,请使用当前时间检查数据库中的时间,如果它大于,例如, 1小时,声明用户fline并相应地更新状态
      That''s good logic, and exactrly how i''d go about it.

      But what if the user doesn''t log out and just exists the browser?

      You''d be smart to take the time of the users last activity, and when showing a page which shows said users last activity, check this time in your database with the current time, and if it is greater than, say, 1hour, declare the user offline and update the status accordingly.



      是的,你是对的:)


      实际上我并没有深入思考。 :p


      然后我们也可以做一个更改。而不是状态标志,仅使用时间。不要使用更新状态字段,但要及时更新。一小时后(或需要多少),如果用户未注销,则声明他已退出。否则,如果他实际退出,请清除时间。


      Yeah, you are right :)

      Actually I didn''t think about in deep. :p

      Then we can also do one change. Instead of status flag, use time only. Don''t update the status field with YES or NO, but update it with time. After one hour (or how much required), if user not logged out, declare him logged out. Else if he actually logs out, clear the time.