PHP 与.htaccess 一起工作

发布于 2024-09-16 07:43:06 字数 379 浏览 2 评论 0原文

对此的任何帮助将不胜感激:

我有一个在 IIS6 IIS7 上运行 php 的网站。我通过启动会话来保护所有 .php 文件。仅当通过 login.php 页面登录启动会话时才能访问 .php 页面

我的所有 .php 文件都位于以下目录中(作为示例):

home/dir

是否可以使用 php 和 .htaccess保护以下目录中的所有文件:

home/dir/files

该目录中的文件是 word 文件、pdf 和其他文件类型。

一旦用户通过login.php登录,我不希望他们在尝试访问home/dir/files时必须重新输入用户名和密码,

我希望我是有道理的。谢谢。

Any help on this would be greatly appreciated:

I have a website running with php on IIS6 IIS7. I am protecting all the .php files by starting a session. The .php pages can only be accessed if the session is started by logging in through the login.php page

All my .php files are in the following directory (using as example):

home/dir

Is it possible to use php and .htaccess to protect all files in the following directory:

home/dir/files

The files in this directory are word files, pdf's and other files types.

Once the user has logged in through login.php I don't want them to have to retype their username and password when trying to access home/dir/files

I hope that I made sense. Thank you.

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

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

发布评论

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

评论(2

朦胧时间 2024-09-23 07:43:06

一般来说,实现此目的的一个好方法是将静态文件放在网站目录结构之外,但仍位于 Web 服务器有权访问它们的位置。然后,由于您无论如何都在使用 PHP,当用户请求文档时,他们实际上会请求一个 PHP 页面来检查用户的权限,然后,如果用户具有足够的权限,则提供该文件。

In general, a good way to do this is to have the static files outside your website directory structure but still somewhere that the web server has permissions to access them. Then, since you're using PHP anyway, when a user requests a document, they would really be requesting a PHP page that checks the user's permissions then, if the user has adequate permissions, serves the file.

瑕疵 2024-09-23 07:43:06

.htaccess 通常与 Apache 而不是 IIS 关联,但请参阅 IIS6 中是否有与 .htaccess 等效的基于文件的文件?

也就是说,也许您可​​以将您的文件目录置于危险之外,并将其放在文档根目录之外的某个位置。然后,您可以通过检查身份验证详细信息的 PHP 脚本控制每个文件的下载。

.htaccess are generally associated with Apache, not IIS, but see Is there a file-based equivalent to .htaccess in IIS6?

That said, perhaps you could put your files directory out of harms way and put it somewhere outside the document root. Then you can control download of each file through a PHP script which checks the authentication details.

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