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 ()...