简体   繁体   中英

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. 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?

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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