Provides various official and user-released code examples and code reference. You are welcome to exchange and learn the code of the user's browsing product record function.
/**
* Vehicle history browsing history
* $ Data vehicle record information
*/
Protected function _ history ($ data)
{
If (! $ Data |! Is_array ($ data ))
{
Return false;
}
// Determine whether there are browsing records in the cookie class
If ($ _ COOKIE ['History _ car'])
{
$ History = unserialize ($ _ COOKIE ['History _ car']);
Array_unshift ($ history, $ data); // Add at the top of the browser record
/* Remove duplicate records */
$ Rows = array ();
Foreach ($ history as $ v)
{
If (in_array ($ v, $ rows ))
{
Continue;
}
$ Rows [] = $ v;
}
/* If the number of records exceeds 5, remove it */
While (count ($ rows)> 5)
{
Array_pop ($ rows); // pop up
}
Setcookie ('History _ car', serialize ($ rows), time () + 3600*24*30 ,'/');
}
Else
{
$ History = serialize (array ($ data ));
Setcookie ('History _ car', $ history, time () + 3600*24*30 ,'/');
}
}
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB