簡體   English   中英

會話毀壞Codeigniter中的問題

[英]Session destroy issue in Codeigniter

我第一次遇到會話破壞的新問題。 在今天之前我會點擊退出使用此:

 function logout()
 {  
      $this->session->unset_userdata("logged_in");    
      $this->session->sess_destroy();      
      redirect(base_url(), 'refresh');
 }

該會議很容易被破壞,但今天它沒有用。 這是我開始會話的代碼。

function checkDataBase()
    {
        $this->load->library('session');
        $email    = $this->input->post('email');
        $password = $this->input->post('password');
        $result   = $this->login_model->contractor_login($email, $password);
        //    die;
        //  echo "<pre>";print_r($result);die;
        if ($result) {
            if (isset($_POST['remember'])) {
                $this->input->set_cookie('email', $_POST['email'], 3600);
                $this->input->set_cookie('password', $_POST['password'], 3600);
            }

            foreach ($result as $row);

            $role_id = 2;

            $session_data = array(
                 'id' => $row->id,
                 'name' => $row->name,
                 'country_id' =>$row->country_id,
                 'category_id' =>$row->category_id,
                 'company_name' =>$row->company_name,
                 'email' =>$row->email,
                 'address1' =>$row->address1,
                 'counties' =>$row->counties,
                 'phone_number' =>$row->phone_number,
                 //'business_status' =>$business_status,
                 'role_id' => $role_id

            );
            $this->session->set_userdata('logged_in', $session_data);
            return TRUE;
        } else {
            $this->session->set_flashdata('message', 'Wrong Username or Password');
            redirect("contractor/login");
        }
    }

從Codeigniter會話類文檔中,關於Flashdata,我們可以閱讀:

CodeIgniter支持“flashdata”或僅可用於下一個服務器請求的會話數據,然后自動清除。 您的問題可能是,當您重定向時,該過程需要多個請求,清除您的flashdata。

要查看是否是這種情況,只需將以下代碼添加到要重定向到的控制器的構造函數中:

$this->session->keep_flashdata('message');

這將使flashdata保留另一個服務器請求,允許它在之后使用。

我得到了會話破壞的解決方案。 實際上問題是我的瀏覽器創建緩存,這就是為什么我認為會話沒有被破壞。 當我研究然后我得到了我的問題的解決方案。

這是我發現解決方案的鏈接。

http://www.robertmullaney.com/2011/08/13/disable-browser-cache-easily-with-codeigniter/ I

我在“應用程序/庫”中創建了一個新文件

使用此代碼

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Output extends CI_Output {

    function nocache()
    {
        $this->set_header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
        $this->set_header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
        $this->set_header('Cache-Control: post-check=0, pre-check=0', FALSE);
        $this->set_header('Pragma: no-cache');
    }

}

/* End of File */

然后我調用了nocache(); 函數進入控制器的constrctor

$這 - >輸出 - >非緩存();

問題已經解決了。

暫無
暫無

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

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