使用.htaccess(和.htpasswd)身份验证时如何注销?

发布于 2024-07-28 23:41:01 字数 437 浏览 8 评论 0原文

可能的重复:
通过 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 技术交流群。

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

发布评论

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

评论(4

风启觞 2024-08-04 23:41:01

在 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.

陌伤浅笑 2024-08-04 23:41:01

浏览器通常不支持此功能,请参阅如何注销?

自浏览器首次启动以来
实施基本身份验证,
网站管理员想要
知道如何让用户注销。
由于浏览器缓存了用户名
和密码进行身份验证
领域,如本文前面所述
教程,这不是一个函数
服务器配置,但是是
让浏览器访问的问题
忘记凭证信息,所以
下次资源是
请求的用户名和密码
必须重新提供。 有
在许多情况下,这是
理想的,例如当使用
公共场所的浏览器,而不是
希望让浏览器保持登录状态
,以便下一个人可以得到
存入您的银行帐户。

然而,虽然这也许是
最常见的问题是
基本身份验证,到目前为止还没有
各大浏览器厂商都有
认为这是一个理想的功能
放入他们的产品中。

因此,这个问题的答案
问题是,你不能。 抱歉。

有些浏览器扩展允许您清除站点的 HTTP 身份验证。
对于 Firefox,WebDeveloper 扩展(无论如何这是我最喜欢的扩展之一)提供了此功能。
其菜单是杂项/清除私有数据/HTTP 身份验证

Browsers usually don't support this, see How do I log out?

Since browsers first started
implementing basic authentication,
website administrators have wanted to
know how to let the user log out.
Since the browser caches the username
and password with the authentication
realm, as described earlier in this
tutorial, this is not a function of
the server configuration, but is a
question of getting the browser to
forget the credential information, so
that the next time the resource is
requested, the username and password
must be supplied again. There are
numerous situations in which this is
desirable, such as when using a
browser in a public location, and not
wishing to leave the browser logged
in, so that the next person can get
into your bank account.

However, although this is perhaps the
most frequently asked question about
basic authentication, thus far none of
the major browser manufacturers have
seen this as being a desirable feature
to put into their products.

Consequently, the answer to this
question is, you can't. Sorry.

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.

向地狱狂奔 2024-08-04 23:41:01

几年前我就遇到过这个问题。 发现每个人都遇到一个问题并且似乎没有人愿意以通用方式解决,这是令人难以置信的令人沮丧。

正如 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.

二货你真萌 2024-08-04 23:41:01

注销是可能的。 您应该实现注销页面,该页面将返回 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.

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