如何刪除特定用戶的會話登錄 (How to remove session login for specific user)


問題描述

如何刪除特定用戶的會話登錄 (How to remove session login for specific user)

我正在為每個用戶創建一個登錄會話。這是我的會話功能:

public function check_login()
{
    $uname  = $this‑>input‑>post('username');
    $passwd = $this‑>input‑>post('password');

    $this‑>form_validation‑>set_rules('username','user_name','required');
    $this‑>form_validation‑>set_rules('password','password','required');

    if( $this‑>form_validation‑>run() == false )
    {
        $this‑>load‑>view('login');
    }
    else
    {
        $this‑>load‑>model('model_login');
        $result = $this‑>model_login‑>query_login();

        if(!$result)
        { $this‑>load‑>view('login'); }
        else
        {
            //Log History
            $id_user                = $this‑>session‑>userdata('id_user');
            $data_log['id_user']    = $this‑>session‑>userdata('id_user');
            $data_log['log_time']   = date("Y‑m‑d H:i:s");
            $data_log['status']     = 1;

            $this‑>model_login‑>insert_log($data_log);

            $data = array( 'log_status' => 1 );
            $this‑>model_login‑>update_log($data,$id_user);

            echo "<script>alert('Login Sukses')</script>";
            redirect(base_url() . 'con_vendor/index');
        }
    }
}

當用戶登錄或註銷時,他們的歷史記錄被記錄到數據庫中(參見日誌歷史註釋)並且他們的登錄狀態更改為 1(這意味著他們在線)。

但是,當用戶註銷時,似乎所有用戶的會話數據都被刪除,而不僅僅是註銷的用戶。在 user_log db 中,僅記錄第一個用戶註銷 ID。下一個用戶ID雖然記錄了註銷時間,但不記錄。

例如:

用戶A登錄,然後用戶B登錄。所有登錄數據都記錄到 user_log 表中。然後用戶 B 註銷,然後用戶 A 註銷。只記錄用戶 B 的會話數據,用戶 A 的會話數據丟失。

這是我的註銷功能:


參考解法

方法 1:

you need to save the sessions into the database and check client session (code to the header.php) if session from database still available the user can be on but if the session has been deleted redirect the user to the logout page. Notice : you can remove the session from the admin panel. ( just a simple mysql code)

(by VahnMohsen TOA)

參考文件

  1. How to remove session login for specific user (CC BY‑SA 2.5/3.0/4.0)

#login #codeigniter #MySQL #PHP #session






相關問題

只允許 oracle db 登錄到特定的應用程序? (Allowing oracle db login only to specific application?)

使用 FB.login 的註冊流程 (Registration flow using FB.login)

asp.net c# sistem login (asp.net c# login system)

Rails 設計登錄不工作 (Rails devise sign in not working)

我在 cakephp 2.4 中遇到了登錄頁面 (I'm getting stuck with login page in cakephp 2.4)

如何刪除特定用戶的會話登錄 (How to remove session login for specific user)

有沒有標準的asp.net認證授權登錄系統? (Is there a standard asp.net authentication authorization login system?)

所有這些網絡平台如何實現不需要用戶反复登錄的長時間登錄會話? (How do all these web platforms achieve a long-time login session that does not require the user to login over and over again?)

Util-Linux 登錄不使用影子密碼 (Util-Linux Login not working with shadow password)

Android Webview Facebook 登錄 (Android Webview Facebook Login)

重置 Bookstack 憑據 (Reset Bookstack Credentials)

輸入正確的詳細信息且未顯示錯誤後,登錄頁面未重定向到 index.php (Login in page not redirecting to index.php after entering correct details with no error displayed)







留言討論