【问题标题】:Can I programmatically log a user out of .htaccess authorization?我可以以编程方式将用户从 .htaccess 授权中注销吗?
【发布时间】:2012-03-07 23:02:29
【问题描述】:

我正在使用 Apache “Auth”安全性来限制对我网站的访问(通过 .htaccess 文件、.htpasswd 文件等中的命令)。

有没有办法通过我的 PHP 脚本取消对用户的授权,从而有效地让他们退出?

【问题讨论】:

  • 答案是:并非如此。以前有人问过这个问题,请在搜索中输入“trac”。
  • 好的,谢谢。我在 unix stackexchange 网站上询问,并没有看到它,但我会搜索“trac”。
  • 在 trac trac 中有一张票是关于包含很多深刻信息的票。至少有一个 SO 问题链接了该链接,但我不记得链接了。

标签: apache php .htaccess


【解决方案1】:

使用这种类型的身份验证,用户名和密码实际上是由浏览器在每个后续请求中发送的。由于无法告诉浏览器“嘿,停止发送这些”,因此无法执行您正在尝试执行的操作。

(但是,如果您有一个涉及处理部分身份验证的 PHP 脚本,您可以设置一个会话变量以进行标记以忽略有效身份验证并假装用户已注销。)

然而,就好的解决方案而言,没有一个。用户将保持登录状态,直到他或她的浏览器决定停止发送标头(通常在浏览器关闭时)。

【讨论】:

    【解决方案2】:
    <?
    // this PHP will cause a logout event, and give the login prompt again
    
    $AuthName='WHAT-EVER'; // must match AuthName in .htaccess.
    header('HTTP/1.0 401 Unauthorized');
    header('Content-type: text/html');
    header('WWW-Authenticate: Basic realm="'.$AuthName.'"');
    
    // now redirect them when they click cancel
    // should be to a page with no password required.
    // use an HTML meta redirect instead of HTTP 
    // so it runs after the auth is cancelled.
    ?>
    <html><head><meta http-equiv='refresh' content='0;../'></head></html>
    

    【讨论】:

      【解决方案3】:

      【讨论】:

        猜你喜欢
        • 2012-06-15
        • 1970-01-01
        • 2011-03-07
        • 1970-01-01
        • 2017-01-15
        • 1970-01-01
        • 2012-01-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多