【问题标题】:Can you store multiple arrays values in session?您可以在会话中存储多个数组值吗?
【发布时间】:2020-02-02 11:37:52
【问题描述】:

我打算将搜索输入保存为会话中的数组。

if ($this->input->post()) {
    $recent_search = array("Country" => $this->input->post('country'), 
                           "State" => $this->input->post('state'),
                           "Building" => $this->input->post('building'), 
                    );

我已将会话中的数组保存为

$this->session->set_userdata('recentSearch',$recent_search);

问题是在每次提交表单后,我都会接受新的数组值。我想将这些输入数组存储到会话中而不删除旧数组。有什么方法可以用吗?

【问题讨论】:

标签: php arrays codeigniter session


【解决方案1】:

我建议您使用本地存储或 cookie 而不是会话。

例子:


$search_cache = [
   'Country' => $this->input->post('country'),
   'State' => $this->input->post('state'),
   'Building' => $this->input->post('building')
];

setcookie( 'recentSearch', $search_cache , time() + 3600 , '/');
var_export($_COOKIE);

【讨论】:

  • 是的,我现在明白了。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
  • 1970-01-01
  • 2010-12-02
  • 2015-06-20
  • 2010-10-11
  • 2010-09-09
  • 2020-01-18
相关资源
最近更新 更多