How does phpcookie record the Web page accessed by a user?

Source: Internet
Author: User
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 )}*/

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.