Check if a Moodle user is online

走远了吗. 提交于 2019-12-24 16:53:17

问题


I need to know if a user is on-line at Moodle, there is a Moodle block for it, but actually it just check if the user had an activity on Moodle in the last X minutes, but in my case that is not useful. There is anyway to know it?


回答1:


As the other answerers say, it isn't possible to see if a user is currently online. As you mentioned, the online users block checks the value of mdl_user.lastaccess. It's probably the best option but even then it depends on the user accessing or refreshing a page. They could be reading a page for 10 minutes for example, so technically still online but it won't show that they are online. Or vice versa, they could have looked at a page and immediately closed it, so it will show they are online but technically not.

Also in my experience, a lot of user's don't log out of Moodle, they just close the page. So its not a reliable way to see if they are currently logged in or not.

For reference, mdl_user.lastaccess is updated by the following sequence:

Going to index.php or any page that uses require_login() which is pretty much most of the pages in Moodle.

This will call user_accesstime_log()

If the mdl_user.lastaccess time hasn't been updated within the last 60 seconds (set by LASTACCESS_UPDATE_SECS) then the mdl_user.lastaccess is updated with the current time()




回答2:


HTTP doesn't allow you to see who else is online in realtime. You send a request, and get a response back from the server. That's it. Of course, you could send a request and get a response back every second to try to simulate a realtime app, but that gets a little messy.

The best way to get real-time connections is through web sockets, which can be accomplished with a few libraries in node. Just google 'node websocket tutorial' and you'll find what you're looking for.

If you want to outsource the websocket stuff, I highly recommend pusher.com, which only requires that you include some javascript on your webpage to interact with their websocket service.

Of course, if you're trying to get this for Moodle, you may be SOL. But I thought I'd try to explain what you would need if you were to do something in real time. Best of luck to you!



来源:https://stackoverflow.com/questions/31989872/check-if-a-moodle-user-is-online

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!