How PHP browses to history
This article mainly introduces the PHP browsing history of the method, involving PHP operation cookie skills, very practical value, the need for friends can refer to the following
The example in this article describes how PHP browsing history is used. Share to everyone for your reference. The implementation method is as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21st 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
/** * Product History View record * $data Product record information */ Private Function _history ($data) { if (! $data | |!is_array ($DATA)) { return false; } Determine if there is a browsing record in the cookie class if ($this->_request->getcookie (' history ')) { $history = Unserialize ($this->_request->getcookie (' history ')); Array_unshift ($history, $data); At the top of the browsing record, add /* Remove duplicate records */ $rows = Array (); foreach ($history as $v) { if (In_array ($v, $rows)) { Continue } $rows [] = $v; } /* If the number of records is 5 extra, remove */ while (count ($rows) > 5) { Array_pop ($rows); Pop } Setcookie (' History ', serialize ($rows), Time () +3600*24*30, '/'); } Else { $history = Serialize (Array ($data)); Setcookie (' History ', $history, Time () +3600*24*30, '/'); } } |
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/966368.html www.bkjia.com true http://www.bkjia.com/PHPjc/966368.html techarticle PHP Browsing History method This article mainly introduces the method of PHP browsing history, involving PHP operation cookie skills, very practical value, the need for friends can refer to this article ...