Home >Backend Development >PHP Problem >How to prohibit video url download in php

How to prohibit video url download in php

藏色散人
藏色散人Original
2020-09-04 09:15:273957browse

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.

How to prohibit video url download in php

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[&#39;token&#39;] = md5("xxx"); //做一个token 用于失效方案
//进入到详情页
}

goVideo.php code is as follows

/** 
     +---------------------------------------------------------- 
     * 生成html video 播放地址 
     +---------------------------------------------------------- 
     * @access public 
     +---------------------------------------------------------- 
     */  
    public function goVideo()  
    {  
       $vid = (int)$_GET[&#39;videoId&#39;]; //数据库存放的资源id
       $data = $this->getInfo($vid); //通过vid 获取 数据库存放的真实资源地址
        if($_SESSION["token"]){  
            unset($_SESSION["token"]); //删除token,保证每次只能播放一次
         
        //页面直接输出视频
        $filePath=$data[&#39;URL&#39;];
        ini_set(&#39;memory_limit&#39;, &#39;512M&#39;);
        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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn