PHP Records users visited products, in the cookie recording products Id,id get product information _php skills

Source: Internet
Author: User
Tags setcookie
1. Test method www.xxx.com/test.php?content_id= own definition, such as: 44
Copy Code code as follows:

$content _id = Array ();//1. Create an array
$content _id[] = $_get[' ContentID ']; 2. Insert the ID into the array

if (Isset ($_cookie[' content_id '))//3. Determine if the COOKIE exists for the first time (if present)
{
$now _content = str_replace ("\", "", $_cookie[' content_id ']);//(4). You can look at the COOKIE, and if something goes wrong with unserialize, I'll remove the slash inside.
$now = unserialize ($now _content); (5). Serialize the string generated by the cookie in the array
foreach ($now as $n => $w) {//(6). There are many elements inside, so I'm going to foreach out the value
if (!in_array ($w, $content _id))//(7). Determine whether this value exists, and if so, I will not insert it into the array;
{
$content _id[] = $w; (8). Inserting into an array
}
}
$content = Serialize ($content _id); (9). Instantiate the array as a string
Setcookie ("content_id", $content, Time () +3600*24); (10). Insert to Cookie

}else {
$content = Serialize ($content _id)//4. Instantiate an array as a string
Setcookie ("content_id", $content, Time () +3600*24); 5. Generate Cookies
}

$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.