Home > Article > Backend Development > Introduction to the usage of PHP setcookie() function_PHP tutorial
Cookies are just like sessions in php, except that one is on the client side and the other is on the server side. Let me introduce the cookie setting and deletion code of setcookie in php in detail.
setcookie() syntax
setcookie (PHP 3, PHP 4, PHP 5)
setcookie -- send a cookie message
Description: bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]] )
Example
Write cookie
The code is as follows
|
Copy code
|
||||||||||||||||||
setcookie("TestCookie", $value);
setcookie("TestCookie", $value, time()+3600, "/~rasmus/", "example.com", 1);
| |||||||||||||||||||
// Print an individual cookie echo $_COOKIE["TestCookie"]; echo $HTTP_COOKIE_VARS["TestCookie"]; // Another way to debug/test is to view all cookies print_r($_COOKIE); ?> Delete cookies
|