【问题标题】:How to echo a single session with Codeigniter?如何使用 Codeigniter 回显单个会话?
【发布时间】:2015-02-14 18:12:35
【问题描述】:

我想阅读单个会话。

这是我设置所有会话的方式:

$data = array(
    'connection'    => true,
    'sender_db'     => $this->input->post('sender_db'),
    'sender_host'   => $this->input->post('sender_host'),
    'sender_user'   => $this->input->post('sender_user'),
    'sender_pw'     => $this->input->post('sender_pw'),
    'receiver_db'   => $this->input->post('receiver_db'),
    'receiver_host' => $this->input->post('receiver_host'),
    'receiver_user' => $this->input->post('receiver_user'),
    'receiver_pw'   => $this->input->post('receiver_pw'),
);
foreach ($data as $key => $value) {
    $this->session->set_userdata($key, $value);
}

这就是我尝试阅读会话sender_host的方式:

var_dump($this->session->get_userdata('sender_host'));

嗯,这给了我一个数组,所有其他会话也存储在:

array(9) {
    ["connection"]=> bool(true)
    ["sender_db"]=> string(12) "datamigrator"
    ["sender_host"]=> string(9) "localhost"
    ["sender_user"]=> string(4) "root"
    ["receiver_db"]=> string(8) "anything"
    ["sender_pw"]=> string(0) ""
    ["receiver_host"]=> string(8) "anything"
    ["receiver_user"]=> string(8) "anything"
    ["receiver_pw"]=> string(8) "anything"
}

如何只获得一个会话?

我认为问题在于我如何设置会话?!

【问题讨论】:

标签: php arrays codeigniter session


【解决方案1】:

试试这个:

构建数组

$data = array(
    'connection' => true,
    'sender_db' => $this->input->post('sender_db'),
    'sender_host' => $this->input->post('sender_host'),
    'sender_user' => $this->input->post('sender_user'),
    'sender_pw' => $this->input->post('sender_pw'),
    'receiver_db' => $this->input->post('receiver_db'),
    'receiver_host' => $this->input->post('receiver_host'),
    'receiver_user' => $this->input->post('receiver_user'),
    'receiver_pw' => $this->input->post('receiver_pw'),
);

设置会话:

$this->session->set_userdata($data);

然后像这样从会话中读取:

$this->session->userdata('sender_host');    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-10
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多