I want to restrict video and photo displays per session. For example, visitor watches 3 videos and when he tries to watch a fourth video he's redirected to a subscription page. I'll be using JWPlayer or native HTML5, doesn't matter, and this would work in WP, but looking to any way to do it with PHP (I'm not an expert by any mean).
So, ideally, this would be teh workflow: 1)visitor watches video1 --> optional message --> you have 2 videos left 2)visitor watches video2 --> optional message --> you have 1 videos left 3)visitor watches video3 --> optional message --> you have 0 videos left 4)visitor tries to watch video4 --> redirect
So far I found ways to limit per bandwidth or per time (only 1 video and then redirect), but I need to serve exactly 3 videos, no matter the time or size, so those solutions won't work. Any idea on how to achieve this?
edit: here's some code to redirect, I really didn't add anything yet because nothing is what I need, but take a 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>
Store a count in the Session (ideally a list of video ID's so they can watch the same video multiple times in the one session), this may be nullified by the user clearing cookies. Otherwise, if your users have an account they must log into, store a history of what they've watched against a database table.
Edit: Now I noticed you're using wordpress here, so I cant' help with adding it to that, but here's an example of a session based approeach
<?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']);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With