Using cookies
function _sethistory ($data)
{
if (! $data | |!is_array ($DATA))
{
return false;
}
Determine if there is a browsing record in the cookie class
if ($_cookie["_producthistory"])
{
$history = Unserialize (stripslashes ($_cookie[' _producthistory '));
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) > 6)
{
Array_pop ($rows); Pop
}
Setcookie (' _producthistory ', serialize ($rows), time () + 3600 * 24 * 30, '/');
}
Else
{
$history = Array ($data);
Setcookie (' _producthistory ', $history, time () + 3600 * 24 * 30, '/');
}
return;
}
I was after a long time to fix, start in window no problem, to the Linux environment can not be deserialized, and finally found that there are special characters caused.
Note:
Serialize () – Converts an array to a string and keeps the data structure intact
Addslashes () – The function adds a backslash before the specified predefined character. These predefined characters are:
Single quotation mark (')
Double quotation marks (")
Back slash (\)
Null
The Stripslashes () function is a reverse operation of addslashes (), which is to delete the backslash added by the addslashes () function.
Unserialize () operates on a single serialized variable and converts it back to the value of PHP. Returns the converted value, which can be an integer, float, string, array, or object. Returns FALSE if the passed string is not serializable.
$_cookie[' Dc_orders ']=serialize ($_session[' dingcan_shoppingcart_data ']);
$cookie _info=unserialize (stripslashes ($_cookie[' dc_orders '));
Phpcms Commodity browsing record and the problems encountered