是否有可能注销用户从一个网站,如果他是使用基本身份验证?

杀死会话是不够的,因为一旦用户通过身份验证,每个请求都包含登录信息,因此用户下次使用相同的凭据访问站点时将自动登录。

目前唯一的解决方案是关闭浏览器,但从可用性的角度来看,这是不可接受的。


当前回答

让用户点击指向https://log:out@example.com/的链接。这将用无效的凭证覆盖现有的凭证;注销它们。

这是通过在URL中发送新的凭证来实现的。在本例中,user="log" password="out"。

其他回答

这是我的注销是如何使用形式工作:

创建基本认证用户注销密码注销 创建目录logout/和添加.htaccess:行'要求用户注销'

RewriteEngine On
AuthType Basic
AuthName "Login"
AuthUserFile /mypath/.htpasswd
require user logout

添加注销按钮,网站的形式如下:

<form action="https://logout:logout@example.com/logout/" method="post">
   <button type="submit">Logout</button>
</form>

Logout /index.php可以是这样的:

<?php
echo "LOGOUT SUCCESS";
header( "refresh:2; url=https://example.com" );
?>

5.9.2022确认支持chrome、edge和三星android网络浏览器

使用会话ID (cookie) 使服务器上的会话ID失效 不接受会话id无效的用户

让用户点击指向https://log:out@example.com/的链接。这将用无效的凭证覆盖现有的凭证;注销它们。

这是通过在URL中发送新的凭证来实现的。在本例中,user="log" password="out"。

我为现代Chrome版本更新了mthoring的解决方案:

function logout(secUrl, redirUrl) {
    if (bowser.msie) {
        document.execCommand('ClearAuthenticationCache', 'false');
    } else if (bowser.gecko) {
        $.ajax({
            async: false,
            url: secUrl,
            type: 'GET',
            username: 'logout'
        });
    } else if (bowser.webkit || bowser.chrome) {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.open(\"GET\", secUrl, true);
        xmlhttp.setRequestHeader(\"Authorization\", \"Basic logout\");\
        xmlhttp.send();
    } else {
// http://stackoverflow.com/questions/5957822/how-to-clear-basic-authentication-details-in-chrome
        redirUrl = url.replace('http://', 'http://' + new Date().getTime() + '@');
    }
    setTimeout(function () {
        window.location.href = redirUrl;
    }, 200);
}

其实很简单。

只需在浏览器中访问以下内容,并使用错误的凭据: http://username:password@yourdomain.com

这应该会“让你退出”。