forked from ifew/php-prevent-video-download
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapper.php
executable file
·23 lines (22 loc) · 1.02 KB
/
wrapper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
ob_start(function($output){
if( (strpos($output,"<video") > -1 || strpos($output,"<audio") > -1 || strpos($output,"<source") > -1 ) && (strpos($output,"<safe") == FALSE) ){
//Check If There is Video On The Page Then Load Defa Protector
// Source Tag Validation isn't need but for safety
//If HTML Contains Safe Tag, Then Not Load Defa Protector
function getURL($matches)
{
$crc = substr(sha1($matches['2']), -8, -1);
$_SESSION['defaprotect' . $crc] = $matches['2'];
return $matches[1] . "/video.php?crc=".$crc;
}
//Super Ugly But Works Better
$output = preg_replace_callback("/(<video[^>]*src *= *[\"']?)([^\"']*)/i", getURL, $output);
$output = preg_replace_callback("/(<source[^>]*src *= *[\"']?)([^\"']*)/i", getURL, $output);
$output = preg_replace_callback("/(<audio[^>]*src *= *[\"']?)([^\"']*)/i", getURL, $output);
}
return $output;
});