Infrastructure
Common methods of Cookies:
$_cookie[' Recordluhuidudu '] get cookies
Setcookie (' Recordluhuidudu ', ", Time () -3600*24*30); Setcookie (field name, data, expiration time); Set cookies
Note
It is also the same way to reset a cookie to invalidate a previous cookie and to delete a cookie:
Setcookie (' Recordluhuidudu ', ", Time () -3600*24*30);
"Code Sample"
/** * Store the supplies ID in a cookie * * @param $id * @return BOOL */Public Function Setcookierecord ($id) {$data = null; if (!isset ($_cookie[' Recordluhuidudu ')) {if (!empty ($id)) {$data [0] = array (' id ' = $id, ' Time ' = Date (' y-m-d h:i:s ', Time ())); }else{return false; }}else{if (!empty ($id)) {$data = $_cookie[' Recordluhuidudu ']; Setcookie (' Recordluhuidudu ', ', Time () -3600*24*30); $data = Json_decode ($data, true); $num = count ($data); Determine if repeat $judge = false; foreach ($data as $index = + $value) {if ($data [$index] [' id '] = = $id) {$data [$index] [' time '] = date (' Y -m-d h:i:s ', Time ()); $judge = true; }} if ($judge) {Setcookie (' Recordluhuidudu ', Json_encode ($data), Time () +3600*24*30); return true; if ($num = =) {for ($i = 0; $i < 9; $i + +) {$data [$i] = $data [$i +1];} $data [9] = arrAY (' id ' = $id, ' time ' = ' date ' (' y-m-d h:i:s ', Time ())); if ($num <10) {$data [$num] = array (' id ' = = $id, ' time ' = = Date (' y-m-d h:i:s ', Time ()) ); }else {return false; }}} setcookie (' Recordluhuidudu ', Json_encode ($data), Time () +3600*24*30); return true; }
This article originates from IT985 Blog