Cookies are often used to identify users. Cookie is a small file that the server stays on the user's computer. When the same computer requests a page through a browser, it sends a cookie at the same time. Through the php Tutorial, you can create and retrieve cookies...
Cookies are often used to identify users. Cookie is a small file that the server stays on the user's computer. When the same computer requests a page through a browser, it sends a cookie at the same time. Through the php Tutorial, you can create and retrieve the cookie value.
How to create a cookie?
The setcookie () function is used to set the cookie.
Note: The setcookie () function must be locatedBefore the tag.
Syntax
Setcookie (name, value, expire, path, domain );
$ Content_id = array (); // 1. create an array $ content_id [] =$ _ get ['tentid']; // 2. insert the connected id to the array (if (isset ($ _ cookie ['content _ id']) // 3. determine whether the cookie exists. if it does not exist for the first time (if it exists) {$ now_content = str_replace ("", "", $ _ cookie ['content _ id']); // (4 ). you can view the cookie. if unserialize is faulty, I have removed the slash $ now = unserialize ($ now_content); // (5 ). convert the string generated by serialize in the cookie into an array foreach ($ now as $ n => $ w) {// (6 ). there are many elements in it, so I want to foreach the value if (! In_array ($ w, $ content_id) // (7 ). determine whether the value exists. if the value exists, I will not insert it into the array; {$ content_id [] = $ w; // (8 ). insert to array }}$ content = serialize ($ content_id); // (9 ). convert the array instance into a string setcookie ("content_id", $ content, time () + 3600*24); // (10 ). insert to cookie} else {$ content = serialize ($ content_id); // 4. convert the array instance into a string setcookie ("content_id", $ content, time () + 3600*24); // 5. generate cookie} $ getcontent = unserialize (str_replace ("", "", $ _ cookie ['content _ id']); /* foreach ($ getcontent as $ row => $ r) {echo $ r; // (value )}*/