Reputation: 5073
I've media website once member is logged successfully it creates session
$_SESSION['login_id'] = $username;
I wonder how to prevent members to watch two channels in same time.
I mean for example if member is viewing page video.php?id=4
and open in new tab page video.php?id=5
it shows him error have to close the page of video.php?id=4
before viewing the new page.
1st thing came into my mind is random token key
that cleared on page exit but i don't know if it good idea or not, does anyone known how to do it or have better idea ! ~ thanks
Upvotes: 2
Views: 99
Reputation: 23642
Just my thoughts
Since the video has to stream, it pings the server
. The session
can have assigned to it, the last video clicked. then once a new video is clicked, the session on the server will use the new video id
and once the first video pings the server and find out the session is pointed at a different page, then the video can return an error message
Alternatively, You could assign an ID
to each instance
of form
OR a hidden field with an ID
, then use AJAX
to ping the server with that ID. If the user tries to request the same form when there's an active ID, it should display an error message.
Upvotes: 1
Reputation: 3911
You could use requests to a php script that tells you if the user is still opening a web page.
For that you can use a loop of timed out ajax requests ( using jQuery for example)
Instead of making Requests you can try and load tiny images ( 1px h/w ) and of course load this image using a php script (you can trick the url using htaccess
),
So when the image is requested, your php script will do the trick (setting the currently watched video) then serve the image (don't forget to set the proper content-type )
and keep loading the image at certain interval (you will need to generate url token to avoid caching ;) )
Serving your videos using php script as proxy, like that you can know when a video has been streamed completely, then if a user request a second video, knowing his is still streaming a previous one, you deny his request, show him an appropriate message or do as you like :)
I guess, using the 2nd solution would be better for you and the visitor, since he would be able to start caching a 2nd video once the 1st one has been cached completely
1st solution will use many request which can overwhelm the network or both the client side and server side
Upvotes: 2
Reputation: 26804
if ($_SESSION['login_id'] = $username && COUNT($_GET['id'])>1 )
Now after you check this condition I don't know what you could do to prevent the user from opening 2 tabs..
Upvotes: 1