The cookie is like a session in PHP, just one on the client is on the server side, let me describe in detail PHP Setcookie to the cookie set and delete code.
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]]])
Cases
Write a cookie
The code is as follows |
Copy Code |
$value = ' something from somewhere '; Setcookie ("TestCookie", $value); Setcookie ("TestCookie", $value, Time () +3600); /* expire in 1 hour */ Setcookie ("TestCookie", $value, Time () +3600, "/~rasmus/", "example.com", 1); ?> |
Read cookies
The code is as follows |
Copy Code |
Print an individual cookie echo $_cookie["TestCookie"]; echo $HTTP _cookie_vars["TestCookie"]; Another-to-debug/test is-to-view all cookies Print_r ($_cookie); ?> |
Delete Cookies
The code is as follows |
Copy Code |
Set the expiration date to one hour ago Setcookie ("TestCookie", "", Time ()-3600); Setcookie ("TestCookie", "", Time ()-3600, "/~rasmus/", "example.com", 1); ?> |
Because of the specific way in which cookies and HTTP are sent, you must transmit all cookies before you export any text. Otherwise, PHP will give a warning and the cookie will not be transmitted. So this is the right thing to do:
The code is as follows |
Copy Code |
Setcookie (' name ', ' Jeff '); echo "Hello everyone!"; ?> |
The following are incorrect:
The code is as follows |
Copy Code |
echo "Hello everyone!"; Setcookie (' name ', ' Jeff '); ?> |
http://www.bkjia.com/PHPjc/628948.html www.bkjia.com true http://www.bkjia.com/PHPjc/628948.html techarticle The cookie is like a session in PHP, just one on the client is on the server side, let me describe in detail PHP Setcookie to the cookie set and delete code. Setcookie () syntax ...