Reputation: 721
We have a streaming site which has a loggin system based on PHP sessions. After the user starts the stream, if another person is connecting with the same account, I need to terminate the first session and kill the page. The only way I can think of is using Ajax, but I'm not sure how secure is that. Is there any way to output the page in php and after the page is served to the user and after that the script to keep checking if another user has logged in with the same account and kill the page? Tried using output buffering and sleep, no luck so far.
Upvotes: 1
Views: 447
Reputation: 19563
First of all, you need to keep track of sessions in a database or other storage system. This data should have a reference to the user. And get cleaned up on a regular basis.
If you kill an existing session, the user in that session wont be pushed out until the next server request. So in the background, you want to 'ping' the server, just make an ajax request, until it fails. On failure, redirect the user back to a login page.
Now this is not foolproof. A client could interfere with, block or redirect the ping requests. But if they were to access another page in your system, they would be forced to login again.
Upvotes: 1