如何使用 php 密码保护流媒体视频 [英] How to password protect streaming videos with php

查看:37
本文介绍了如何使用 php 密码保护流媒体视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 php/.htaccess 密码保护 quicktime 流视频的最佳方法是什么.它们是使用 rtsp 流式传输的,但如有必要,我可以使用其他格式.

What is the best way to password protect quicktime streaming videos using php/.htaccess. They are being streamed using rtsp, but I can use other formats if necessary.

我知道如何使用 php 进行身份验证,但我不确定如何设置身份验证以保护流文件 url,这样用户就不能只是复制 url 并共享它.

I know how to do authentication with php, but I'm not sure how to setup authentication so that will protect the streaming files urls so that a user can't just copy the url and share it.

还是我想多了,我可以使用普通的身份验证方案并将文件放在受保护的目录中?

Or am I overthinking this and I can just use a normal authentication scheme and place the files in a protected directory?

推荐答案

nginx 和 lighttpd 网络服务器都有可以从 PHP 返回的 X-Send-File 标头.因此,您可以在 PHP 中进行检查,然后有条件地将文件服务器输出.

Both nginx and lighttpd web servers have X-Send-File headers you can return from PHP. So you can do your checks in PHP and then conditionally server out the file.

if (check_user_can_access()){
    header('X-sendfile: /path/to/file');
} else {
    header('HTTP/1.1 403 Fail!');
}

Lighttpd 还有一个名为 mod_secure_download 的简洁模块,它允许您以编程方式生成仅在短时间内有效的网址.

Lighttpd also has a neat module called mod_secure_download that allows you to programatically generate a URL that will only be valid for a short time period.

Nginx 以及可能的 lighttpd 允许您限制下载速度,因此您不会以比消耗速度更快的速度发送流数据.

Nginx, and possibly lighttpd, allow you to cap the download speed, so you're not sending out streaming data faster than it can be consumed.

无论哪种方式,您都希望使用您的网络服务器来提供文件.通过 PHP 为它们提供服务是可能的,但速度很慢.

Either way, you want to use your web server for serving files. Serving them through PHP is possible, but slow.

这篇关于如何使用 php 密码保护流媒体视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆