/***
* Add content to cookies
*/
Public Function Addcookie ($content) {
$trace =cookie (' trace ');//Read the original value
if (!empty ($trace))
{
Get the value inside the cookie and cut it into an array with a comma
$history = Explode (', ', $_cookie[' trace ');
Inserts the item ID that is currently being browsed at the beginning of this array
Array_unshift ($history, $content);
Remove duplicate values in the array
$history = Array_unique ($history);
When the length of the array is greater than 5, the loop executes the code inside
while (count ($history) > 5)
{
POPs the last cell of the array until its length is less than or equal to 5
Array_pop ($history);
}
Write the array with a comma to the cookie and set its expiration time to one week
Cookie (' Trace ', implode (', ', $history), 3600 * 24*7);
}
Else
{
If the cookie is empty, the current browsed item ID is written to the cookie, which occurs only when the site is first browsed
Cookie (' Trace ', $content, 3600 * 24 * 7);
}
}
This article is from "Tiger Brother's Blog" blog, please be sure to keep this source http://7613577.blog.51cto.com/7603577/1567321
PHP implements the Web browsing Footprint feature