简体   繁体   中英

How to prevent viewing two pages in same time

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

At first thought

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)

Hint:

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 ;) )


A second solution could be

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


Both Solutions would not track a user that is using more than one browser, which means he would have more than one session, unless the user is registered and logged in

if ($_SESSION['login_id'] = $username && COUNT($_GET['id'])>1 )

现在,在您检查了这种情况之后,我不知道如何阻止用户打开2个标签。

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.

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