我隐藏HLS URL使用PHP输出文件,但不工作


I hide HLS URL using PHP to output files but doesn't work

这是我原来的URL: http://xxx.xxx.xxx.xxx/01/MV01/index.m3u8出于安全考虑,我将所有HLS文件移到网站(/var/www/html)的文档根之外。IE。将它们移动到/var/www/video/01/mv01/indexM3u8包括所有.ts文件在同一个文件夹。

然后在文档根目录下创建。htaccess:

. htaccess:

RewriteEngine on
RewriteCond %{REQUEST_URI} .*ts$|.*m3u8$ [NC]
RewriteRule ^(.*) auth.php?file=$1 [NC,L]

这将重定向所有需求并获得php输出的文件。

auth.php:

//
Some codes to check authorization first.
//
$reqpath = strip_tags($_GET['file']);
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache,must-revalidate");
header("Cache-Control: post-check=0, pre-check=0",false);
header("Pragma: no-cache");
header('Content-type:application/force-download');
if (strpos($_GET['file'],".ts")>1) header("Content-type: video/MP2T");
if (strpos($_GET['file'],".m3u8")>1) header("Content-type: application/x-mpegURL");
@readfile("/var/www/video/".$reqpath);

我的目的是当用户访问http://xxx.xxx.xxx.xxx/01/MV01/index.m3u8时,他仍然可以播放视频。

结果是:它在iOS和Android上运行良好,但不能在PC上运行,包括jwplayer和VLC。

jwplayer上的错误信息是" error loading player: No playable sources found"VLC上的错误信息是"主输入错误:没有合适的demux模块用于'http://xxx.xxx.xxx.xxx/01/MV01/index.m3u8'

**我使用从apple.com下载的HLS示例文件,所以我认为。m3u8和。ts文件没有问题。

帮助!

我终于解决了。

为什么只能在iOS和Android上玩而不能在PC上玩?我想问题应该在PHP输出,所以我试图改变HTTP头,然后我找到了答案。

再添加一个标题:

header('Content-Length: ' . filesize("/var/www/video/".$reqpath));

这里所有的header

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache,must-revalidate");
header("Cache-Control: post-check=0, pre-check=0",false);
header("Pragma: no-cache");
header('Content-type:application/force-download');
header('Content-Disposition: attachment; filename='.basename($filename));
header('Content-Length: ' . filesize("/var/www/video/".$reqpath));
header('Content-Type: '.mime_content_type("/var/www/video/".$reqpath));