我可以使用$ _SESSION来限制对目录的访问吗? [英] Can I use $_SESSION to limit access to directories?

查看:64
本文介绍了我可以使用$ _SESSION来限制对目录的访问吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录脚本,可以为经过身份验证的用户创建一个SESSION。但

经过身份验证的用户仍然需要访问特定目录(

包含要下载的文件)。我的托管服务提供商让我用htaccess保护

目录,但这意味着已经过身份验证的用户必须

第二次在受htaccess保护的目录下载内容时,
浏览器窗口。 AFAIK,没有办法将凭证传递给

htaccess。如何保护经过身份验证的用户的文件和/或
目录?还有替代htaccess吗?


提前致谢。

I have a login script that creates a SESSION for authenticated users. But
authenticated users still need access to particular directories (which
contain files for download). My hosting provider lets me protect
directories with htaccess, but this means an already authenticated user must
enter credentials a second time in the pop up dialog that appears in the
browser window when attempting to download something from an
htaccess-protected directory. AFAIK, there is no way to pass credentials to
htaccess. How do I protect an authenticated user''s files and/or
directories? Is there an alternative to htaccess?

Thanks in advance.

推荐答案

***dekoescribió/写道(星期六,2005年3月12日19:59:23 GMT):
*** deko escribió/wrote (Sat, 12 Mar 2005 19:59:23 GMT):
我有一个登录脚本,为经过身份验证的用户创建一个SESSION。


你已完成95%的工作。现在......


您可以使用这些凭据来保护目录吗?不,你不能,就像我知道的那样。 PHP永远不会处理由

Apache,JPEG文件,PDF文件等创建的目录列表。


您是否可以使用这些凭据来保护PHP文件?当然。这种最简单的

方式:


< ;?


if(!isset(
I have a login script that creates a SESSION for authenticated users.
You already have 95% of work done. Now...

Can you use these credentials to protect directories? No, you cannot, as
far as I know. PHP will never handle the directory listings created by
Apache, JPEG files, PDF files, etc.

Can you use these credentials to protect PHP files? Sure. This simpliest
way:

<?

if( !isset(


_SESSION [''authenticated_user_id''])||
_SESSION[''authenticated_user_id'']) ||


_SESSION [''authenticated_user_id'']!= 666){

die( ''未经授权'');

}


?>

如何保护经过身份验证的用户的文件和/或目录?
_SESSION[''authenticated_user_id'']!=666 ){
die(''Unauthorized'');
}

?>
How do I protect an authenticated user''s files and/or directories?




典型的选择是将它们移到公共网站目录之外,其中它们不能由Apache提供服务。然后不要链接文件,链接用PHP编写的
下载脚本。

-

- +álvaroG。Vicario - Burgos,西班牙

+ - http://www.demogracia.com (la web de humor barnizada para la intemperie)

++ Manda tus dudas al grupo,no amibuzón

- +将你的问题发送给小组,而不是我的邮箱

-



The typical option is moving them outside the public web directory, where
they cannot be served by Apache. Then do not link the files, link a
download script written in PHP.
--
-+ álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Manda tus dudas al grupo, no a mi buzón
-+ Send your questions to the group, not to my mailbox
--


这篇关于我可以使用$ _SESSION来限制对目录的访问吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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