<small id='QsvHc'></small><noframes id='QsvHc'>

    <legend id='QsvHc'><style id='QsvHc'><dir id='QsvHc'><q id='QsvHc'></q></dir></style></legend>
      <bdo id='QsvHc'></bdo><ul id='QsvHc'></ul>
    <tfoot id='QsvHc'></tfoot>
      <i id='QsvHc'><tr id='QsvHc'><dt id='QsvHc'><q id='QsvHc'><span id='QsvHc'><b id='QsvHc'><form id='QsvHc'><ins id='QsvHc'></ins><ul id='QsvHc'></ul><sub id='QsvHc'></sub></form><legend id='QsvHc'></legend><bdo id='QsvHc'><pre id='QsvHc'><center id='QsvHc'></center></pre></bdo></b><th id='QsvHc'></th></span></q></dt></tr></i><div id='QsvHc'><tfoot id='QsvHc'></tfoot><dl id='QsvHc'><fieldset id='QsvHc'></fieldset></dl></div>

      PHP 服务 MP4 - Chrome“显示临时标头/请求尚未完成"漏洞

      时间:2024-08-22

        1. <tfoot id='Rj6QH'></tfoot>
            <legend id='Rj6QH'><style id='Rj6QH'><dir id='Rj6QH'><q id='Rj6QH'></q></dir></style></legend>

            <small id='Rj6QH'></small><noframes id='Rj6QH'>

              • <bdo id='Rj6QH'></bdo><ul id='Rj6QH'></ul>
                <i id='Rj6QH'><tr id='Rj6QH'><dt id='Rj6QH'><q id='Rj6QH'><span id='Rj6QH'><b id='Rj6QH'><form id='Rj6QH'><ins id='Rj6QH'></ins><ul id='Rj6QH'></ul><sub id='Rj6QH'></sub></form><legend id='Rj6QH'></legend><bdo id='Rj6QH'><pre id='Rj6QH'><center id='Rj6QH'></center></pre></bdo></b><th id='Rj6QH'></th></span></q></dt></tr></i><div id='Rj6QH'><tfoot id='Rj6QH'></tfoot><dl id='Rj6QH'><fieldset id='Rj6QH'></fieldset></dl></div>

                  <tbody id='Rj6QH'></tbody>
              • 本文介绍了PHP 服务 MP4 - Chrome“显示临时标头/请求尚未完成"漏洞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想在允许他们观看视频之前检查用户的订阅,为此我使用 PHP 与 Stripe 检查用户的订阅,然后使用 PHP 脚本 将 MP4 提供给浏览器

                I want to check for users' subscription before allow them to see the video, for this reason I use PHP to interact with Stripe to check for user's subscription, and than used PHP script to serve MP4 to browser

                第一次在 Google Chrome 中播放视频时效果很好(使用 HTML5 播放器)...但是当我关闭视频并再次播放时,视频不再播放......我也不能重新加载当前页面.就像服务器停止工作一样.

                It works fine the first time a video is played in Google Chrome (Using HTML5 player)... But when I close the video and play it again, the video doesn't play anymore... I can NOT also reload the current page. It's like server stops working.

                当我检查第一个视频请求(播放的那个)时,在时间"选项卡中我看到:注意:请求尚未完成!"(截图如下)

                When I inspect the 1st video request (the one which played), in the Timing tab i see: "CAUTION: request is not finished yet!" (screenshot below)

                当我检查第二个视频请求(那个没有播放)时,在标题选项卡中显示[警告标志] 显示临时标题"(下面的屏幕截图)

                When I inspect the 2nd video request (the one did not play), in Headers tab it says "[caution sign] Provisional headers are shown" (screenshot below)

                在 Safari 或 Firefox 中一切正常

                everything worked as expected in Safari or Firefox

                有人知道发生了什么吗?再次播放视频的唯一方法是关闭当前选项卡,再次进入该站点.重新加载不起作用!

                Anyone has any idea what is going on? The only way for the video to play again is to close the current tab, enter the site again. Reloading doesn't work!

                推荐答案

                我建议你使用下面的函数,而不是你当前的'streaming script'.如果您传递 $filename_output,它将作为下载文件提供文件,否则它将流式传输!

                I suggest you use the following function instead of your current 'streaming script'. If you pass $filename_output, it will serve the file as download, and it will stream otherwise!

                它应该适用于所有浏览器.

                It should work in every browser.

                serveFile('/where/my/vid.mp4');

                serveFile('/where/my/vid.mp4');

                public function serveFile($filename, $filename_output = false, $mime = 'application/octet-stream')
                {
                    $buffer_size = 8192;
                    $expiry = 90; //days
                    if(!file_exists($filename))
                    {
                        throw new Exception('File not found: ' . $filename);
                    }
                    if(!is_readable($filename))
                    {
                        throw new Exception('File not readable: ' . $filename);
                    }
                
                    header_remove('Cache-Control');
                    header_remove('Pragma');
                
                    $byte_offset = 0;
                    $filesize_bytes = $filesize_original = filesize($filename);
                
                    header('Accept-Ranges: bytes', true);
                    header('Content-Type: ' . $mime, true);
                
                    if($filename_output)
                    {
                        header('Content-Disposition: attachment; filename="' . $filename_output . '"');
                    }
                
                    // Content-Range header for byte offsets
                    if (isset($_SERVER['HTTP_RANGE']) && preg_match('%bytes=(d+)-(d+)?%i', $_SERVER['HTTP_RANGE'], $match))
                    {
                        $byte_offset = (int) $match[1];//Offset signifies where we should begin to read the file            
                        if (isset($match[2]))//Length is for how long we should read the file according to the browser, and can never go beyond the file size
                        {
                            $filesize_bytes = min((int) $match[2], $filesize_bytes - $byte_offset);
                        }
                        header("HTTP/1.1 206 Partial content");
                        header(sprintf('Content-Range: bytes %d-%d/%d', $byte_offset, $filesize_bytes - 1, $filesize_original)); ### Decrease by 1 on byte-length since this definition is zero-based index of bytes being sent
                    }
                
                    $byte_range = $filesize_bytes - $byte_offset;
                
                    header('Content-Length: ' . $byte_range);
                    header('Expires: ' . date('D, d M Y H:i:s', time() + 60 * 60 * 24 * $expiry) . ' GMT');
                
                    $buffer = '';
                    $bytes_remaining = $byte_range;
                
                    $handle = fopen($filename, 'r');
                    if(!$handle)
                    {
                        throw new Exception("Could not get handle for file: " .  $filename);
                    }
                    if (fseek($handle, $byte_offset, SEEK_SET) == -1)
                    {
                        throw new Exception("Could not seek to byte offset %d", $byte_offset);
                    }
                
                    while ($bytes_remaining > 0)
                    {
                        $chunksize_requested = min($buffer_size, $bytes_remaining);
                        $buffer = fread($handle, $chunksize_requested);
                        $chunksize_real = strlen($buffer);
                        if ($chunksize_real == 0)
                        {
                            break;
                        }
                        $bytes_remaining -= $chunksize_real;
                        echo $buffer;
                        flush();
                    }
                }
                

                这篇关于PHP 服务 MP4 - Chrome“显示临时标头/请求尚未完成"漏洞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:打开下载的 zip 文件会创建 cpgz 文件吗? 下一篇:无法使用大量变量重定向 - 标头可能不包含多个标头,检测到新行.在

                相关文章

              • <legend id='nPPgw'><style id='nPPgw'><dir id='nPPgw'><q id='nPPgw'></q></dir></style></legend>

                  <i id='nPPgw'><tr id='nPPgw'><dt id='nPPgw'><q id='nPPgw'><span id='nPPgw'><b id='nPPgw'><form id='nPPgw'><ins id='nPPgw'></ins><ul id='nPPgw'></ul><sub id='nPPgw'></sub></form><legend id='nPPgw'></legend><bdo id='nPPgw'><pre id='nPPgw'><center id='nPPgw'></center></pre></bdo></b><th id='nPPgw'></th></span></q></dt></tr></i><div id='nPPgw'><tfoot id='nPPgw'></tfoot><dl id='nPPgw'><fieldset id='nPPgw'></fieldset></dl></div>

                    <small id='nPPgw'></small><noframes id='nPPgw'>

                    • <bdo id='nPPgw'></bdo><ul id='nPPgw'></ul>

                    <tfoot id='nPPgw'></tfoot>