使用.htaccess(和.htpasswd)身份验证时如何注销?
可能的重复:
通过 PHP 进行 HTTP 身份验证注销
您好,
我的网站上有一些功能使用 .htaccess
和 .htpasswd
。 当用户尝试访问此内容时,系统会提示他们输入详细信息。 他们输入详细信息并进入并可以看到东西等。一切正常。
我的问题是如何为这种类型的身份验证创建注销
功能。 我知道他们可以关闭浏览器窗口以“注销”。 但这并不理想。 你会给我什么建议?
谢谢。
Possible Duplicate:
HTTP authentication logout via PHP
Hi
I have a some functionality on my website protected using .htaccess
and .htpasswd
.
When users attempt to access this, they get prompt to enter details. They enter their details and get in and can see stuff etc. All works fine.
My question is how do I create a logout
functionality for this type of authentication. I know that they can close the browser window to "Logout". But this is not ideal. What would you suggest to me?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 Firefox 和 Chrome 上测试。 您可以做的是将用户发送到 http://logout:[电子邮件受保护]。 这会将他们当前的用户名/密码替换为注销/注销(可能是任何无效的用户/密码组合),并且由于他们现在的用户名/密码错误,他们将必须再次登录才能访问该网站。
在 Opera 上这不起作用,因为您可以同时拥有多个用户名/密码。 它在 IE 上也不起作用,因为 IE 似乎不支持 http://username:[电子邮件受保护] 网址。
Tested on firefox and chrome. What you can do is send the user to http://logout:[email protected]. This will replace their current username/password with logout/logout (it could be any invalid user/pass combination) and since they now have the wrong username/password, they will have to login again to access the site.
On opera this does not work, because you can have several usernames/passwords at the same time. It didn't work on IE either, because IE does not appear to support http://username:[email protected] URLs.
浏览器通常不支持此功能,请参阅如何注销?
有些浏览器扩展允许您清除站点的 HTTP 身份验证。
对于 Firefox,WebDeveloper 扩展(无论如何这是我最喜欢的扩展之一)提供了此功能。
其菜单是
杂项/清除私有数据/HTTP 身份验证
。Browsers usually don't support this, see How do I log out?
There are browser extensions that allow you to clear the HTTP authentication for a site.
For Firefox the WebDeveloper extension (which is one of my favourtie extensions anyway) offers this feature.
The menu for this is
Miscellaneous/Clear Private Data/HTTP Authentication
.几年前我就遇到过这个问题。 发现每个人都遇到一个问题并且似乎没有人愿意以通用方式解决,这是令人难以置信的令人沮丧。
正如 HTTP 身份验证中的注销功能不足中所述,我认为答案是更改 RFC 以允许超时并支持注销按钮。 作者关于服务器能够发送“注销”标头的额外建议实际上消除了对任何客户端用户代理支持的需要,因为网站可以简单地在网页上包含指向以下 URL 的链接:返回必要的响应代码和/或标头以使当前会话无效。
I ran into this issue several years ago. It is incredibly frustrating to discover there is a problem everyone is having and no one seems to want to solve in a general way.
As noted in Inadequate Logout functionality in HTTP Authentication I think the answer is to change the RFC to allow timeouts and support a log out button. The author's additional suggestion that the server be able to send a "log out" header would actually eliminate the need for any client user agent support since websites could simply include a link on a web page to a URL that returns the necessary response code and/or header to invalidate the current session.
注销是可能的。 您应该实现注销页面,该页面将返回 HTTP 401,直到用户输入错误的登录信息,然后重定向到其他地方。 浏览器会记住接受的最新登录信息,因此会覆盖正确的登录信息。
但这有点无法使用,因为它需要用户的配合。
It IS kind of possible to log out. You should implement logout page, which will return HTTP 401, until the user enter BAD login information, and then redirect somewhere else. Browser remembers the latest login information accepted, and therefore overrides correct login.
But this is kinda unusable, cos it needs user's cooperation.