How to log out user from web site using BASIC authentication?

后端 未结 22 1750
感情败类
感情败类 2020-11-22 04:00

Is it possible to log out user from a web site if he is using basic authentication?

Killing session is not enough, since, once user is authenticated, each request co

22条回答
  •  时光取名叫无心
    2020-11-22 04:41

    I updated mthoring's solution for modern Chrome versions:

    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);
    }
    

提交回复
热议问题