├── LICENSE ├── README.md ├── index.php ├── small.mp4 ├── tested_chrome.png ├── tested_safari.png ├── video.php └── wrapper.php /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Chitpong Wuttanan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Prevent user download video from browser (HTML5, PHP) 2 | 3 | Tested on Chrome 102.0.5005.61 (Official Build) (x86_64), Safari 15.4 (17613.1.17.1.13) 4 | 5 | ![Chrome](tested_chrome.png) 6 | 7 | ![Safari](tested_safari.png) 8 | 9 | ## Prequisition 10 | - PHP 8 11 | 12 | ## How to use 13 | - Download this code and extract all files 14 | - Open index.php 15 | 16 | ### License 17 | MIT License. 18 | 19 | ### Original from 20 | 21 | - [Defa-Protector-Protect-HTML5-Video-From-Download](https://sourceforge.net/projects/defaprotecthtml5videodownload/files/latest/download) Made with Love From Juthawong Naisanguansee , Bangkok - Thailand http://www.ampareengine.com 22 | 23 | ### Solution from 24 | 25 | - [Han Lin Yap - gist:3906826](https://gist.github.com/codler/3906826) -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /small.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ifew/php-prevent-video-download/610f0380c8d77f79f510466fd3dbbaee7b9e3f29/small.mp4 -------------------------------------------------------------------------------- /tested_chrome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ifew/php-prevent-video-download/610f0380c8d77f79f510466fd3dbbaee7b9e3f29/tested_chrome.png -------------------------------------------------------------------------------- /tested_safari.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ifew/php-prevent-video-download/610f0380c8d77f79f510466fd3dbbaee7b9e3f29/tested_safari.png -------------------------------------------------------------------------------- /video.php: -------------------------------------------------------------------------------- 1 | $end) ? $end : $c_end; 40 | if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) { 41 | header('HTTP/1.1 416 Requested Range Not Satisfiable'); 42 | header("Content-Range: bytes $start-$end/$size"); 43 | exit; 44 | } 45 | $start = $c_start; 46 | $end = $c_end; 47 | $length = $end - $start + 1; 48 | fseek($fp, $start); 49 | header('HTTP/1.1 206 Partial Content'); 50 | } 51 | header("Content-Range: bytes $start-$end/$size"); 52 | header("Content-Length: ".$length); 53 | 54 | $opts['http']['header'] = "Range: bytes=" . ($start-$end)/$size . ", 55 | Content-Type: video/mp4, 56 | Accept-Ranges: bytes, 57 | Content-Disposition: inline;, 58 | Content-Transfer-Encoding: binary\n,". 59 | "Connection: close"; 60 | 61 | $opts['http']['method'] = "GET"; 62 | $cong = stream_context_create($opts); 63 | ob_end_clean(); 64 | 65 | readfile($file, false, $cong); 66 | 67 | exit(); 68 | } 69 | -------------------------------------------------------------------------------- /wrapper.php: -------------------------------------------------------------------------------- 1 | -1 || strpos($output," -1 || strpos($output," -1 ) && (strpos($output,"]*src *= *[\"']?)([^\"']*)/i", "getURL", $output); 18 | $output = preg_replace_callback("/(]*src *= *[\"']?)([^\"']*)/i", "getURL", $output); 19 | $output = preg_replace_callback("/(]*src *= *[\"']?)([^\"']*)/i", "getURL", $output); 20 | } 21 | return $output; 22 | }); 23 | 24 | --------------------------------------------------------------------------------