简体   繁体   English

用PHP保护ASX文件

[英]Protecting an ASX file in PHP

I have a members only area on my site where users can login and view Windows Media streaming content. 我的网站上只有会员区,用户可以在其中登录和查看Windows Media流内容。

I have created a PHP script to serve the ASX file however I cannot validate this with session information. 我已经创建了一个PHP脚本来提供ASX文件,但是我无法使用会话信息对此进行验证。 I think this is because the WMP is making the request and not a php page. 我认为这是因为WMP正在发出请求,而不是php页面。

Can anyone suggest an elegant way to protect ASX files? 谁能建议一种保护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
}

What I would do is incorporate the PHP session ID into the .asx request. 我要做的是将PHP会话ID合并到.asx请求中。 Normally this identifier is stored in a cookie, and passed to PHP on each page request. 通常,此标识符存储在cookie中,并在每次页面请求时传递给PHP。 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. 在这种情况下,WMP不会一起发送cookie,因此您无法知道请求是否已通过身份验证。

When you output the download link for the ASX file, tack on the session identifier as a GET variable: 当输出ASX文件的下载链接时,将会话标识符添加为GET变量:

$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. 现在,当您在download_asx_file.php的顶部调用session_start()时,它应该正确找到并加载您的会话,并允许您像往常一样进行身份验证。

Note : The SID constant is evaluated to PHPSESSID=12345678 (or whatever that user's session happens to be) 注意 :SID常数的计算值为PHPSESSID=12345678 (或任何用户会话碰巧发生的情况)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM