Cookies are often used to identify users. Cookies are small files that the server leaves on the user's computer. Whenever the same computer requests a page through a browser, it sends cookies as well. Through the PHP tutorial, you can create and retrieve the value of a cookie.
How do I create cookies?
The Setcookie () function is used to set cookies.
Note: the Setcookie () function must precede the <html> label.
Syntax
Setcookie (name, value, expire, path, domain);
$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 a lot of elements, 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 do not insert into the array;
{
$content _id[] = $w; (8). Inserting into an array
}
}
$content = Serialize ($content _id); (9). Instantiate an array as a string
Setcookie ("content_id", $content, Time () +3600*24); (10). Insert INTO 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)
}*/