简体   繁体   English

如何使用PHP代码获取Openfire Server中用户的上次注销时间

[英]How to get Last Logout time of user in Openfire Server using php code

How to get Last Logout time of user in Openfire Server using php code. 如何使用PHP代码获取Openfire Server中用户的上次注销时间。 How i will achieve this I am new on Openfire. 我将如何实现这一点我是Openfire的新手。

I googled a lot. 我google了很多。 But haven't found any article about my questions. 但是没有发现任何关于我的问题的文章。 Is there any way to get "last seen" or "last activity" date from Openfire server? 有没有办法从Openfire服务器获得“上次看到”或“最后一次活动”日期?

Please help me. 请帮我。 Thanks in advance. 提前致谢。

You can use XMPPHP library to manage XMPP connection to Openfire in PHP; 您可以使用XMPPHP库来管理PHP中与Openfire的XMPP连接; there are several fork from the project originally hosted on Google Code, for example: 最初托管在Google Code上的项目有几个fork,例如:

Example of usage are easy to find, however here are some of them: 使用示例很容易找到,但以下是其中一些:

In your case, after having created your connection to XMPP server (Openfire) with: 在您的情况下,在创建了与XMPP服务器(Openfire)的连接后:

$conn = new XMPPHP_XMPP(...);
$conn->connect();

you can send a generic XML message with $conn->send($xml); 您可以使用$conn->send($xml);发送通用XML消息$conn->send($xml); or a specific IQ message with $conn->sendIq(...); $conn->sendIq(...);的特定IQ消息$conn->sendIq(...); .

Follow xep-0012 doc to create appropriate XML to obtain Last Activity info for a user. 按照xep-0012 doc创建适当的XML以获取用户的Last Activity信息。

If you don't want to communicate on XMPP and you have access to Openfire's database, then you can also query the database for last seen time. 如果您不想在XMPP上进行通信并且您可以访问Openfire的数据库,那么您还可以查询数据库上次查看的时间。

Table: ofPresence 表:ofPresence

You can query for "offlineDate" against "username" and you will get time in milliseconds: 001448886257729 您可以针对“用户名”查询“offlineDate”,您将获得以毫秒为单位的时间:001448886257729

Whenever a user comes online (sends his presence to Openfire Server), his entry is removed from this table. 每当用户上线(将他的存在发送到Openfire服务器)时,他的条目将从该表中删除。 So for an online user, you won't get any record. 因此,对于在线用户,您将无法获得任何记录。

Hope it will help. 希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM