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?
Asked
Active
Viewed 611 times
2 Answers
0
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.

Community
- 1
- 1

Sid Malani
- 2,078
- 1
- 13
- 13
-
That's what I was thinking. However, how do I identify EVERY user that is accessing that page? For an example: The notification would read: "A User, B User, and C user are also viewing this ticket." – Kevin Oluseun Karimu Nov 24 '11 at 23:15
-
Your server variable can be an array. So when user gets to the page you add to array, when user leaves delete and Ajax simply loads the array and displays. – Sid Malani Nov 24 '11 at 23:19
-
Can you give me a sample code? I still don't understand how a SERVER variable will keep track of every user accessing the page. – Kevin Oluseun Karimu Nov 25 '11 at 04:59
0
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)

Adam Fowler
- 1,750
- 1
- 17
- 18
-
Ok. So what you mean is that while the user is looking at the page the ajax will constantly send updates to the database in a row that is the record for the user viewing the database? – Kevin Oluseun Karimu Nov 25 '11 at 05:02
-
Also, we need to identify those who left the page. How will we do this? – Kevin Oluseun Karimu Nov 25 '11 at 05:03
-
you can set some JS code to be executed when the user leaves the page, otherwise it will timeout after a certain amount of time, so you dont have to worry about someone being stuck "viewing" the page – Adam Fowler Nov 26 '11 at 16:11