PHP 和 htpasswd
我有这样的结构:
/home
/home/dir1
/home/dir2
现在,当有人访问 /home 时,系统会要求他提供用户名和密码(以表单形式),然后我在 PHP 中为 /home 的其余文件设置会话信息。 现在 /home/dir1 和 /home/dir2 受 htpasswd 保护,但用户名和密码相同。 我不希望用户在转到 /home/dir1 时再次重新输入用户名和密码...此外,当我从 /home 注销时,我也想从 /home/dir1 注销。 您能否就如何实现这一目标提出建议?
I have a structure like this:
/home
/home/dir1
/home/dir2
Now when someone goes to /home, he is asked for username and password (in a form) and I set session information in PHP for the remaining files of /home. Now /home/dir1 and /home/dir2 are protected by htpasswd but the same username and password. I dont want the user to re-enter their username and password again when they go to /home/dir1... Also when I logout from /home, I want to logout from /home/dir1 also. Can you please advice on how to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该是默认行为。
也就是说,如果您使用 Apache 和 .htaccess 文件来设置 HTTP 身份验证,则应用于目录的任何规则也将应用于其子目录,并且浏览器将将其视为一次性登录。
如果您希望它采取不同的行为,即如果您希望将站点的某些部分视为需要完全独立的登录,则可以使用 .htaccess 中的 AuthName 指令为每个部分指定一个“领域”。 更多信息请参见此处。 但是,如果您不这样做,它将始终被视为同一登录的所有部分。
HTTP 身份验证的问题是无法“注销”,至少除非浏览器提供该功能。 大多数浏览器允许您注销的唯一方法是结束浏览器会话(即关闭浏览器)。 是的,一旦您执行此操作,您将退出 /home、/home/dir1、/home/dir2 以及所有站点/领域上的所有目录。
This should be the default behaviour.
That is, if you are using Apache and .htaccess files to set up HTTP authentication, any rules you apply to a directory will also apply to its child directories, and it will be treated by the browser as all one login.
If you want it to act differently, ie if you wanted some sections of the site to be treated as requiring a completely separate login, you would specify a 'realm' for each section using the AuthName directive in .htaccess. More information here. However, if you don't do that, it will always be treated as all part of the same login.
The thing about HTTP authentication is that there is no way to 'log out', at least not unless the browser provides that feature. The only way most browsers will allow you to log you out is by ending the browser session (ie closing the browser). And yes, once you do this, you'll be logged out of /home, /home/dir1, /home/dir2 and all directories on all sites/realms.
在 Apache 中,只要两个文件夹具有相同的 AuthName 并且位于同一站点,它们就应该共享一个密码。
这两个目录可能都有一个 .htaccess 文件,如下所示:
In Apache as long as both folders have the same AuthName and are on the same site they should share a password.
Both directories might have a .htaccess file like so: