如何使用网址在网络上播放视频,但不能通过直接链接访问


How to make video play on web by using url, but can not access by direct link?

如何使用网址在网络上播放视频,但不能通过直接链接访问?

现在我使用 jw 播放器

<script type="text/javascript">
                    jwplayer("mediaplayer1889082201").setup({
                            flashplayer: "jwplayer/jwplayer.flash.swf",
                            file: "http://testhost.com/myproject/files/1/video/coursecreeklruprr4nags7ee1codeschool_756.mp4",
                            image: "http://testhost.com/myproject/files/1/video/coursecreeklruprr4nags7ee1codeschool_756.jpg",
                            width: "800",
                            height: "510",
                            stretching: "uniform",
                            skin: "jwplayer/jwplayer-skins-free/six.xml",
                            abouttext: "myproject",
                            aboutlink: "myproject",
                    });
            </script>

所以我可以使用 http://testhost.com/myproject/files/1/访问文件夹(通过检查元素查看此链接)

我想在jw播放器上播放视频。但我不希望用户通过直接 url 访问包含视频的文件夹的网络。

谢谢你。

好的,我知道您希望将视频文件提供给脚本,但您不希望用户能够导航到视频 URL 并从那里下载/查看它。

使用 PHP 的快速示例

将代码更改为:

<script type="text/javascript">
                    jwplayer("mediaplayer1889082201").setup({
                            flashplayer: "jwplayer/jwplayer.flash.swf",
                            file: "video.php?file=coursecreeklruprr4nags7ee1codeschool_756.mp4",
                            image: "http://testhost.com/myproject/files/1/video/coursecreeklruprr4nags7ee1codeschool_756.jpg",
                            width: "800",
                            height: "510",
                            stretching: "uniform",
                            skin: "jwplayer/jwplayer-skins-free/six.xml",
                            abouttext: "myproject",
                            aboutlink: "myproject",
                    });
            </script>

如您所见,我们正在向video.php发送文件请求,然后,仅当引荐来源是您能够显示它的网页时,我们才会创建为视频提供服务的文件。

继续并在同一文件夹中创建video.php

首先,我们需要检查 url 中是否给出了文件,如下所示:

<?php
if(isset($_GET['file']) {
}

然后我们检查引荐来源网址是否是您的页面,如下所示:

if (strpos($ref,'testhost.com/myproject/files/1') !== 0){
}

如果这是您的页面,我们可以开始提供您的文件,如下所示:

$path = 'video/' . $_GET['file'];
header("X-Sendfile: $path");

所以整个事情在一起:

<?php
if(isset($_GET['file']) {
    if (strpos($ref,'testhost.com/myproject/files/1') !== 0){
        $path = 'video/' . $_GET['file'];
        header("X-Sendfile: $path");
    }
}

注意;这是一个非常快速的示例,而不是一个安全且随时可用的脚本!它们必须是内置的安全检查,即使文件不存在,您也在提供文件,因此仍然必须进行这种检查以使其准备好使用。

祝你的项目好运。

下:

stretching: "uniform",

加:

type: "mp4",

这样,如果没有文件扩展名,JW 播放器可以读取文件。

相关文章: