This article mainly introduces the use of cookies in PHP, including creating/updating cookies, deleting cookies, fetching cookie values, and so on, which friends can refer to in the following
1. Create/update cookie code as follows: Setcookie ($cookieName, $value, time () + seconds); Example: Create a cookie with the name username, The value is ZS, expires in 2 weeks code as follows: Setcookie ("UserName", "Zs", Time () +2*7*24*3600); If you do not set the time, it will not be saved to the cookie file. When the browser is not off, it can be accessed. When the browser is closed, it cannot be accessed. Example: code is as follows: Setcookie ("Age", "18"); 2. Take the value of the cookie code as follows: $_cookie[$cookieName]; Example: Take out the value of UserName, put in the variable $uname code as follows: $uName =$_cookie[' UserName '; when the values It is generally judged whether it is empty, and then take the value operation. The above value-taking operation is generally written as follows: Code: if (!empty ($_cookie[' UserName ')) { $uName =$_cookie[' UserName ']; } 3. Delete the specified cookie code as follows: Setcookie ($cookieName, Value,time ()-seconds);/or Setcookie ($cookiename, "); or Setcookie ($cookiename, NULL); Example: Delete UserName code as follows: Setcookie ("UserName", "Zs", Time ()-3600); 4. Delete all cookies for the current session code as follows: foreach ($_cookie as $key => $val) {Setcookie ($key, "", Time () -100);} when no CWhen Ookie, the file that saves cookies on this computer will also be deleted.