You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在stream.php页面隐藏地址栏中的m3u8?PHP及替代方案咨询

How to Hide M3U8 URL from Address Bar

Absolutely, you can hide the m3u8 URL from the address bar using PHP, and there are alternative approaches too depending on your Windows 10 Chrome setup with native HLS playback. Let's break this down clearly:

This method uses stream.php as a middleman to serve the m3u8 content (and its video segments) while keeping the address bar pointed to stream.php. Here's how to implement it:

Basic Proxy for M3U8

First, create stream.php with this code to serve your main m3u8 file directly:

<?php
// Set the correct MIME type for HLS streams
header('Content-Type: application/vnd.apple.mpegurl');
header('Cache-Control: no-cache');

// Replace this with the path to your actual m3u8 file (local or remote URL)
$target_m3u8 = 'path/to/your/video.m3u8';

// Read and output the m3u8 content to the browser
echo file_get_contents($target_m3u8);
?>

Now when you visit yourdomain.com/stream.php, Chrome will load and play the HLS stream, and the address bar stays on stream.php instead of the raw m3u8 URL.

Handling Video Segments (If Needed)

If your m3u8 references relative-path .ts segments, you'll need to proxy those too (otherwise Chrome will try to load them directly from the wrong path). Update stream.php to handle both m3u8 and segment files:

<?php
// Get the requested file (defaults to your main m3u8 if no parameter is provided)
$requested_file = $_GET['file'] ?? 'main.m3u8';

// Define the base directory where your video files (m3u8 + ts) are stored
$base_dir = __DIR__ . '/your-video-folder/';
$full_path = $base_dir . $requested_file;

// Return 404 if the file doesn't exist
if (!file_exists($full_path)) {
    http_response_code(404);
    exit('File not found');
}

// Set the correct MIME type based on file extension
$ext = pathinfo($requested_file, PATHINFO_EXTENSION);
match ($ext) {
    'm3u8' => header('Content-Type: application/vnd.apple.mpegurl'),
    'ts' => header('Content-Type: video/MP2T'),
    default => header('Content-Type: application/octet-stream'),
};

// Output the file content efficiently
readfile($full_path);
?>

Then edit your main m3u8 file to update segment paths to use the proxy:

- 1.ts
- 2.ts
+ stream.php?file=1.ts
+ stream.php?file=2.ts

This ensures all stream requests go through stream.php, keeping the address bar clean.

Bonus: Clean Up the URL (Optional)

If you want to avoid the ?file= parameter in the address bar, use URL rewriting (Apache mod_rewrite or Nginx) to make URLs like stream/1.ts point to stream.php?file=1.ts.

For Apache, add this to your .htaccess:

RewriteEngine On
RewriteRule ^stream/(.*)$ stream.php?file=$1 [L]

Then your m3u8 segments can use paths like stream/1.ts, and the address bar stays tidy.

Alternative Solutions

If PHP isn't your preferred approach, here are two other options:

Nginx Reverse Proxy

If you have Nginx set up, configure it to serve the m3u8 file under a clean URL without exposing the real path. Add this to your Nginx server block:

location /stream {
    alias /path/to/your/actual/video.m3u8;
    types {
        application/vnd.apple.mpegurl m3u8;
        video/MP2T ts;
    }
}

Visiting yourdomain.com/stream will serve the m3u8 content, with the address bar showing /stream instead of the m3u8 path.

Frontend Player Page

Create a simple HTML page (e.g., player.html) that loads the m3u8 via JavaScript, so the address bar shows the player page URL instead of the m3u8:

<!DOCTYPE html>
<html>
<head>
    <title>Video Player</title>
</head>
<body>
    <video controls width="800"></video>
    <script>
        async function initPlayer() {
            // Fetch the m3u8 content via your PHP proxy or directly (if CORS allows)
            const response = await fetch('stream.php');
            const blob = await response.blob();
            const streamUrl = URL.createObjectURL(blob);
            
            const video = document.querySelector('video');
            video.src = streamUrl;
            await video.load();
        }
        initPlayer();
    </script>
</body>
</html>

Visiting player.html will load the stream without showing the m3u8 URL in the address bar.


内容的提问来源于stack exchange,提问作者David Baez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:14:11