在 PHP 中保护 ASX 文件

发布于 2024-07-29 04:13:58 字数 172 浏览 3 评论 0原文

我的网站上有一个仅限会员的区域,用户可以在其中登录并查看 Windows Media 流媒体内容。

我已经创建了一个 PHP 脚本来提供 ASX 文件,但是我无法使用会话信息来验证它。 我认为这是因为 WMP 发出请求而不是 php 页面。

谁能建议一种优雅的方法来保护 ASX 文件?

I have a members only area on my site where users can login and view Windows Media streaming content.

I have created a PHP script to serve the ASX file however I cannot validate this with session information. I think this is because the WMP is making the request and not a php page.

Can anyone suggest an elegant way to protect ASX files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

堇年纸鸢 2024-08-05 04:13:59

你可以试试这个:

//$user->isAuthenticated is only for ilustration, use whatever method you
//use to check if the user is authenticated
if($user->isAuthenticated()) {
      $asx = file_get_contents("/path/to/my/file.asx");
      header("Content-type: video/x-ms-asf");
      echo $asx;
} else {
      //Tell the user that he can't view this asx
}

You can try this:

//$user->isAuthenticated is only for ilustration, use whatever method you
//use to check if the user is authenticated
if($user->isAuthenticated()) {
      $asx = file_get_contents("/path/to/my/file.asx");
      header("Content-type: video/x-ms-asf");
      echo $asx;
} else {
      //Tell the user that he can't view this asx
}
阳光①夏 2024-08-05 04:13:58

我要做的是将 PHP 会话 ID 合并到 .asx 请求中。 通常,该标识符存储在 cookie 中,并在每次页面请求时传递给 PHP。 在这种情况下,WMP 不会一起发送 cookie,因此您无法知道请求是否经过身份验证。

当您输出 ASX 文件的下载链接时,将会话标识符附加为 GET 变量:

$download_link = "http://myserver.com/download_asx_file.php?"
$download_link .= "f=$file_id&";
$download_link .= htmlspecialchars(SID);

现在,当您在 download_asx_file.php 顶部调用 session_start() 时,它会应该正确找到并加载您的会话,并允许您正常进行身份验证。

注意:SID 常量的计算结果为 PHPSESSID=12345678(或用户会话发生的任何内容)

What I would do is incorporate the PHP session ID into the .asx request. Normally this identifier is stored in a cookie, and passed to PHP on each page request. In this case WMP is not sending a cookie along, so you have no way of knowing whether or not the request is authenticated or not.

When you output the download link for the ASX file, tack on the session identifier as a GET variable:

$download_link = "http://myserver.com/download_asx_file.php?"
$download_link .= "f=$file_id&";
$download_link .= htmlspecialchars(SID);

Now when you call session_start() at the top of download_asx_file.php it should find and load your session correctly, and allow you to authenticate as normal.

Note: The SID constant is evaluated to PHPSESSID=12345678 (or whatever that user's session happens to be)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文