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)
}*/