Detect Users Viewing Same Webpage, or URL

爷,独闯天下 提交于 2019-12-11 02:59:57

问题


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. For an example: /ticket.php?a=10000&tid=987654. Where tid is the ticket id number. 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? Session variable? Javascript? Both?


回答1:


Use unix timestamps in a database, so you can set a timeout. have ajax send requests while the user is still looking at the ticket.

then use a foreach loop and filter all the active timestamps, output username or id.

send response back to your client in json (unless your ghetto enough to use XML)




回答2:


Ajax and server variable should do the trick.

On load you update server variable On unload update server variable When on page Ajax keeps updating webpage with current status

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.

Is there Java HashMap equivalent in PHP?



来源:https://stackoverflow.com/questions/8263291/detect-users-viewing-same-webpage-or-url

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