Limit html5 video display per session?

I want to limit the display of videos and photos per session. For example, a visitor watches 3 videos, and when he tries to watch the fourth video, he is redirected to the subscription page. I will use JWPlayer or my own HTML5, it does not matter, and it will work in WP, but looking at any way to do it with PHP (I am not an expert in any way).

So, ideally, this would be a workflow: 1) a visitor watches video1 → an optional message → you have 2 videos left 2) a visitor watches video2 → an optional message → you have 1 video 3) a visitor watches video3 → an optional message → you have 0 video 4) the visitor tries to watch the video4 → redirection

So far, I have found ways to limit bandwidth or time (only 1 video, and then redirect), but I need to serve exactly 3 videos, regardless of time and size, so these solutions will not work. Any idea on how to achieve this?

edit: here is some code to redirect, I really didn’t add anything, because nothing is what I need, but look:

<script src="text/javascript">
function vidplay(){
    var video = document.getElementById('video');
    video.play();
    video.addEventListener('ended',function(){
        window.location = 'http://SUBSCRIBE_PAGE';
    });
}
</script>
<video controls id="video" width="640" height="360" onclick="vidplay()">
    <source src="video/video.mp4" type="video/mp4" />
</video>
+3
source share
1 answer

( - , ), , cookie. , , , , .

: , Wordpress , , ,

<?php

// Obviously use your variable here
$ID_OF_VIDEO_HERE = $_REQUEST['video'];

if(isset($_SESSION) === false)
  session_start(); // Start PHP session management
if(isset($_SESSION['videos_viewed']) === false)
  $_SESSION['videos_viewed'] = array();

if(isset($_SESSION['videos_viewed'][$ID_OF_VIDEO_HERE]) === FALSE AND count($_SESSION['videos_viewed']) >= 3)
{
  // Redirect the User
  header('location: http://SUBSCRIBE_PAGE');
  exit();
}
else
{
  // Add current video ID to list
  $_SESSION['videos_viewed'][$ID_OF_VIDEO_HERE] = true;
}

// JUST FOR TESTING
var_dump($_SESSION['videos_viewed']);

?>
+3

All Articles