【问题标题】:cakephp logout is not working perfectlycakephp 注销无法正常工作
【发布时间】:2015-07-25 04:52:13
【问题描述】:

当用户第一次登录时,用户会在单击注销按钮时注销。但是如果用户在清除浏览器的cookies之前再次登录并尝试退出,用户将无法退出。有什么帮助吗?我正在使用 cakephp 2.5.6

public function logout() {
        $this->redirect($this->Auth->logout());
    }

//应用控制器

class AppController extends Controller {
         public $components = array(
        'DebugKit.Toolbar',
        'Session',
        'Auth' => array(
            'loginRedirect' => false,
            'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
            'authError' => 'You must be logged in to view this page.',
            'loginError' => 'Invalid Username or Password entered, please try again.',
            'authenticate' => array(
                'Authenticate.MultiColumn' => array(
                    'fields' => array(
                        'username' => 'email',
                        'password' => 'password'
                    ),
                    'columns' => array('email'),
                    'userModel' => 'User',
                    'scope' => array('User.status' => 1)
                )
            )
        ));

    }

//webroot 中的.htaccess

<IfModule mod_deflate.c>
    #The following line is enough for .js and .css
    AddOutputFilter DEFLATE js css

    #The following line also enables compression by file content type, for the following list of Content-Type:s
    AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml

    #The following lines are to avoid bugs with some browsers
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 
</IfModule>
<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

【问题讨论】:

  • 在重定向之前尝试在注销操作中销毁 cookie ($this-&gt;Cookie-&gt;destroy();) 和/或会话 ($this-&gt;Session-&gt;destroy();)。
  • 你得到上述问题的解决方案了吗...?我的朋友也有同样的问题。参考:stackoverflow.com/questions/33776887/…

标签: php .htaccess cakephp mod-rewrite cakephp-2.0


【解决方案1】:

您的问题可能与缓存相关,并且是由 mod_expires.c 中的某行引起的。将以下标头添加到您的注销功能(并删除会话和 cookie 以防万一)应该可以解决问题。

public function logout() {
    header('pragma: no-cache'); 
    header('Cache-Control: no-cache, must-revalidate');
    $this->response->disableCache();
    $this->Session->delete('Auth.User');
    $this->Session->delete('User');
    $this->Session->destroy();
    $this->Cookie->destroy();
    return $this->redirect($this->Auth->logout());
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    • 2015-07-28
    • 2013-06-28
    • 2017-06-30
    相关资源
    最近更新 更多