PHP implements the Web browsing Footprint feature

Source: Internet
Author: User

/***

* 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.