在search_list.php中添加历史记录:

/*记录搜索历史记录*/
if (!empty($_COOKIE[‘ECS’][‘keywords’])){
  $history = explode(‘,’, $_COOKIE[‘ECS’][‘keywords’]);

  array_unshift($history, $keywords); //在数组开头插入一个或多个元素
  $history = array_unique($history);  //移除数组中的重复的值,并返回结果数组。

  setcookie(‘ECS[keywords]’, implode(‘,’, $history), gmtime() + 3600 * 24 * 30);
}else{
  setcookie(‘ECS[keywords]’, $keywords, gmtime() + 3600 * 24 * 30);
}

在 search.php 中取出历史记录
if (!empty($_COOKIE[‘ECS’][‘keywords’])){
  $histroy = explode(‘,’,$_COOKIE[‘ECS’][‘keywords’]);
  foreach ($histroy as $key=>$val){
    $histroy_list[$key][‘histroy’] = $val;
  }
}

相关文章:

  • 2021-05-29
  • 2021-12-31
  • 2021-09-26
  • 2022-12-23
  • 2021-09-04
  • 2022-01-15
  • 2022-12-23
  • 2021-05-10
猜你喜欢
  • 2021-09-28
  • 2022-12-23
  • 2022-12-23
  • 2021-07-07
  • 2022-02-07
  • 2021-05-21
  • 2022-01-16
相关资源
相似解决方案