簡體   English   中英

codeigniter身份驗證:重定向到主頁

[英]codeigniter authentication: redirecting to home page

我是Codeigniter框架的新手。 我正在嘗試建立身份驗證系統。

身份驗證正常。 我的問題是,成功登錄后,當我單擊瀏覽器中的“后退”按鈕時,它將再次定向到登錄頁面。 我想將其重定向到主頁本身。 我想重新加載主頁而不是索引頁面(索引頁面是登錄頁面,成功登錄后將轉到主頁)

我該怎么做

提前致謝

在控制器中使用重定向:

function index()
{
    if ($this->session->userdata['logged_in']) // or whatever you use
    {
        redirect ('/controller/home');
    }
    else
    {
         // show login - post login form to /controller/do_login
    }
 }
 function do_login()
 {
     // check login form and set user session
     redirect('/controller/home'); // or index - does the same...
 }
 function home()
 {
     // show home page
 }

這個簡單的示例顯示了如何在輸出登錄屏幕之前檢查用戶是否已登錄,然后在控制器中使用重定向。

在某些瀏覽器/ Web服務器組合中,我發現必須設置頁面的頁眉才能從服務器實際重新加載。 否則,結果可能是即使登錄后按回車鍵仍會顯示登錄屏幕; 沒有查詢到服務器。 您可以在htaccess中進行設置,但可以在CI語法中進行設置,然后在標頭中輸出HTML:

$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
$this->output->set_header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); 

設置頁面,使其始終在后按時重新加載。

登錄成功后即可使用

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

暫無
暫無

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

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