1. Test method www.xxx.com/test.php?content_id=define by yourself, such as: 44
Copy code The code is as follows:
$content_id = array(); //1. Create an array
$content_id[] = $_GET['contentid']; //2. Insert the received ID into the array
if(isset($_COOKIE['content_id'])) //3. Determine whether the cookie exists. It does not exist for the first time (if it exists)
{
$now_content = str_replace("\" , "", $_COOKIE['content_id']);//(4). You can check the cookie. If there is a problem with unserialize, I removed the slash inside
$now = unserialize( $now_content); //(5). Deinstantiate 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 need to foreach the value
if(!in_array($w,$content_id)) //(7). Determine whether this value exists. If it exists, I will not insert it into the array;
{
$content_id[] = $w; //(8). Insert into array
}
}
$content= serialize($content_id); //(9). Instantiate the array into String
setcookie("content_id",$content, time()+3600*24); //(10). Insert into cookie
}else {
$content= serialize($ content_id); //4. Instantiate the array 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)
}*/
http://www.bkjia.com/PHPjc/323398.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323398.htmlTechArticle1. Test method www.xxx.com/test.php?content_id=Defined by yourself, such as: 44 Copy code The code is as follows: $content_id = array(); //1. Create an array $content_id[] = $_GET['contentid']; //2. Connect...