2014-09-11 74 views
0

我目前正在研究一個CodeIgniter和IonAuth項目,並且我遇到了這個問題。CodeIgniter和IonAuth'如果用戶登錄'

場景:當我登錄時,我仍然可以訪問登錄頁面。我想要做的是消除這種訪問,因爲用戶已經登錄

這是在我的身份驗證類我的索引方法:

function index(){ 

     if (!$this->ion_auth->logged_in()) 
     { 
      //redirect them to the login page 
      redirect('auth/login', 'refresh'); 
     } 
     elseif($this->ion_auth->logged_in()) 
     { 
      //redirect them to the index page if logged in 
      redirect('/', 'refresh'); 
     } 
     elseif (!$this->ion_auth->is_admin()) 
     { 
      //redirect them to the home page because they must be an administrator to view this 
      redirect($this->config->item('base_url'), 'refresh'); 
     } 
} 

任何想法將真棒!

回答

2

打開auth控制器。回到登錄方法。在頂部添加以下行:

if($this->ion_auth->logged_in()) 
{ 
    //redirect them to the index page if logged in 
    redirect('/', 'refresh'); 
} 

此外,Ion_auth附帶的auth控制器實際上只是一個示例,應該用作參考。一定要閱讀所有相關文件。

編輯:請注意,使用 '刷新' 爲重定向有它的用途,但可能沒有必要在這種情況下。下面是對信息:

+1

謝謝你的回覆!我會盡快檢查! – yowza 2014-09-11 03:16:50

+1

非常感謝,你真的幫了我很多!保持好狀況! – yowza 2014-09-11 03:22:49