Home >Backend Development >PHP Problem >How to prohibit video url download in php
How to disable video url downloads in php: first set the "detail.html" template content; then make a token for the invalidation solution; then obtain the real resource address stored in the database through vid in the php file; finally Delete the token and ensure that the video can only be played once at a time.
Recommended: "PHP Video Tutorial"
php prevents video resources from being downloaded
If the resource address is: http://xxx.com/videoData/xxx.mp4, playback can be achieved;
detail.html template content
<video controls="controls" autoplay="autoplay"> <source type="video/ogg" src="xxx.com/goVideo.php?video=1" /><!--这样的地址他们就醉了吧,真实地主保护住了 而且每次进入详情页播放完了,重新进入detail链接方法中,才能播放 --> Your browser does not support the video tag. </video>
detail.php control layer Content
// 先进入详情页 publicfunction detail(){ $_SESSION['token'] = md5("xxx"); //做一个token 用于失效方案 //进入到详情页 }
goVideo.php code is as follows
/** +---------------------------------------------------------- * 生成html video 播放地址 +---------------------------------------------------------- * @access public +---------------------------------------------------------- */ public function goVideo() { $vid = (int)$_GET['videoId']; //数据库存放的资源id $data = $this->getInfo($vid); //通过vid 获取 数据库存放的真实资源地址 if($_SESSION["token"]){ unset($_SESSION["token"]); //删除token,保证每次只能播放一次 //页面直接输出视频 $filePath=$data['URL']; ini_set('memory_limit', '512M'); header("Pragma: public"); header("Expires: 0"); header("Content-Type: application/octet-stream"); //文件mime类型 //header("Content-Disposition: attachment; filename=video11.mp4;" ); //文件名$filename //header("Content-Length: 83995"); //文件大小$fsize ob_clean(); flush(); //ob_end_clean(); @readfile($filePath); } }
The above is the detailed content of How to prohibit video url download in php. For more information, please follow other related articles on the PHP Chinese website!