簡體   English   中英

cakephp注銷無法正常運行

[英]cakephp logout is not working perfectly

用戶首次登錄時,單擊“注銷”按鈕將使用戶注銷。 但是如果用戶在清除瀏覽器的cookie之前再次登錄並嘗試注銷,則用戶將無法注銷。 有幫助嗎? 我正在使用cakephp 2.5.6

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

// AppController的

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

    }

//.htaccess在webroot中

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

您的問題可能與緩存有關,並且是由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());
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM