简体   繁体   English

检测查看相同网页或URL的用户

[英]Detect Users Viewing Same Webpage, or URL

I have a ticketing system that will allow any users to view any ticket they wish to select. 我有一个票务系统,该系统将允许任何用户查看他们希望选择的任何票证。 Each ticket will share the same page. 每个票证将共享同一页面。 (ex. ticket.php) The URL will contain unique parameters to identify the ticket. (例如ticket.php)URL将包含用于标识票证的唯一参数。 For an example: /ticket.php?a=10000&tid=987654. 例如:/ticket.php?a=10000&tid=987654。 Where tid is the ticket id number. 其中,tid是票证编号。 I would like to detect if more than one user is viewing the ticket and show this as a notification in the webpage if the condition is true. 我想检测是否有多个用户正在查看票证,如果条件为真,则将其显示为网页中的通知。 How do I go about doing this? 我该怎么做呢? Would I have to use PHP Server variable? 我必须使用PHP Server变量吗? Session variable? 会话变量? Javascript? Javascript? Both? 都?

Ajax and server variable should do the trick. Ajax和服务器变量应该可以解决问题。

On load you update server variable On unload update server variable When on page Ajax keeps updating webpage with current status 在加载时,您更新服务器变量在卸载时,更新服务器变量在页面上时,Ajax不断更新具有当前状态的网页

Have a look at this post. 看看这篇文章。 All you have to do is store one of these array_map in a server variable with page name as the key. 您所要做的就是将其中一个array_map存储在以页面名称为键的服务器变量中。

Is there Java HashMap equivalent in PHP? 在PHP中是否有等效的Java HashMap?

Use unix timestamps in a database, so you can set a timeout. 在数据库中使用unix时间戳,因此可以设置超时。 have ajax send requests while the user is still looking at the ticket. 当用户仍在查看票证时,让ajax发送请求。

then use a foreach loop and filter all the active timestamps, output username or id. 然后使用foreach循环并过滤所有活动的时间戳,输出用户名或ID。

send response back to your client in json (unless your ghetto enough to use XML) 使用json将响应发送回您的客户端(除非您的贫民窟足以使用XML)

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

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