Home > Backend Development > PHP Tutorial > How to browse history in php, browse history in php_PHP tutorial

How to browse history in php, browse history in php_PHP tutorial

WBOY
Release: 2016-07-13 10:04:20
Original
948 people have browsed it

How to browse history in php, browse history in php

The example in this article describes the method of browsing history in php. Share it with everyone for your reference. The specific implementation method is as follows:

/**
 * 商品历史浏览记录
 * $data 商品记录信息
 */
private function _history($data)
{
  if(!$data || !is_array($data))
  {
    return false;
  }
  //判断cookie类里面是否有浏览记录
  if($this->_request->getCookie('history'))
  {
    $history = unserialize($this->_request->getCookie('history'));
    array_unshift($history, $data); //在浏览记录顶部加入
    /* 去除重复记录 */
    $rows = array();
    foreach ($history as $v)
    {
      if(in_array($v, $rows))
      {
        continue;
      }
      $rows[] = $v;
    }
    /* 如果记录数量多余5则去除 */
    while (count($rows) > 5)
    {
      array_pop($rows); //弹出
    }
    setcookie('history',serialize($rows),time()+3600*24*30,'/');
  }
  else
  {
    $history = serialize(array($data));
    setcookie('history',$history,time()+3600*24*30,'/');
  }
}
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/965563.htmlTechArticleHow to browse history in php, php browsing history This article describes the method of browsing history in php. Share it with everyone for your reference. The specific implementation method is as follows: /** * Product...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template