codeigniter会话不返回用户代理或IP地址或会话ID

时间:2018-04-21 15:17:07

标签: codeigniter session

我在我的控制器中使用此代码:

public function index() {
    $this->load->library('session');
    echo "<pre>";
    print_r($this->session->all_userdata());
    echo "</pre>";
}

这就是结果:

Array
(
    [__ci_last_regenerate] => 1524275027
    [identity] => admin
    [username] => admin
    [email] => admin
    [user_id] => 1
    [old_last_login] => 1524182225
    [last_check] => 1524274694
)

我使用codeigniter 3.1 with ion_Auth

那么如何获取所有数据,如user_agent,ip,......?

1 个答案:

答案 0 :(得分:0)

Codigniter会话库是为3.0版重新编写的,并且在最新版本3.1.8之前有一些错误修复。

在早期的CI版本(2.x)中,会话数据阵列默认有4个项目:

“SESSION_ID”,
“IP_ADDRESS”,
“USER_AGENT”,
“last_activity”

现在,在新的CI版本中,您仍然可以像这样访问这些数据(来自文档:)

    session_id: session_id()
    ip_address: $_SERVER['REMOTE_ADDR']
    user_agent: $this->input->user_agent() (unused by sessions)
    last_activity: Depends on the storage, no straightforward way. Sorry!

见:https://www.codeigniter.com/user_guide/libraries/sessions.html#accessing-session-metadata 并且:https://www.codeigniter.com/userguide3/installation/upgrade_300.html#step-6-update-your-session-library-usage