PHPCookei code used to record historical user browsing information. phpcookei_PHP tutorial

Source: Internet
Author: User
Tags set cookie
PHPCookei is the code used to record the user's historical browsing information. PHPCookei code used to record historical user browsing information. phpcookei [basic] common Cookie methods: $ _ COOKIE ['recordluhuidudu] get Cookiesetcookie ('recordluhuidudu, ", time () PHP Cookei code that records the user's historical browsing information, phpcookei

[Basics]

Common Cookie methods:

$ _ COOKIE ['recordluhuidudu'] to get the Cookie
Setcookie ('recordluidudu', ", time ()-3600*24*30); setcookie (field name, data, expiration time); set Cookie

Note]

To reset a Cookie, you need to invalidate the previous Cookie. The same method is also used to delete the Cookie:
Setcookie ('recordluidudu', ", time ()-3600*24*30 );

[Sample code]

/*** Save the product id to the Cookie ** @ param $ id * @ return bool */public function setCookieRecord ($ id) {$ data = null; if (! Isset ($ _ COOKIE ['recordluhuidudu']) {if (! Empty ($ id) {$ data [0] = array ('id' = $ id, 'Time' = date ('Y-m-d H: I: s ', time ();} else {return false ;}} else {if (! Empty ($ id) {$ data = $ _ COOKIE ['recordluidudu']; setcookie ('recordluidudu ', '', time ()-3600*24*30 ); $ data = json_decode ($ data, true); $ num = count ($ data); // judge whether the request is repeated $ judge = false; foreach ($ data as $ index => $ value) {if ($ data [$ index] ['id'] = $ id) {$ data [$ index] ['Time'] = date ('Y-m-d H: I: S', time (); $ judge = true ;}} if ($ judge) {setcookie ('recordluhuidudu', json_encode ($ data), time () + 3600*24*30); return true ;} if ($ num = 10) {for ($ I = 0; $ I <9; $ I ++) {$ data [$ I] = $ data [$ I + 1];} $ data [9] = array ('id' => $ id, 'Time' => date ('Y-m-d H: I: S', time ();} if ($ num <10) {$ data [$ num] = array ('id' => $ id, 'Time' => date ('Y-m-d H: I: S ', time ();} else {return false ;}} setcookie ('recordluidudu', json_encode ($ data), time () + 3600*24*30 ); return true ;}

This article is from the IT985 blog

Http://www.bkjia.com/PHPjc/1098977.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1098977.htmlTechArticlePHP Cookei records the user's history browsing information code, phpcookei [basic] Cookie common method: $ _ COOKIE ['recordluidudu'] get Cookie setcookie ('recordluidudu ',", time ()...

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.