Cookies are a very frequent use of knowledge in development, telling you about the common sense and use of cookies in PHP learning.
What is a cookie?
As defined in the official documentation, a cookie is a way for a server or script to maintain information on a client workstation under the HTTP protocol. A cookie is a small text file that is saved by a Web service on a user's browser and contains information about the user being accessed. It is a different solution to the session, but also solves the problem of maintaining a state between multiple things, while maintaining a neat URL, which can be saved as a script on the client machine, by sending an HTTP header that contains specific data and has the following format. Set a cookie on the user machine:
Set-cookie:cookie_name=myfirstcookie; [Expires=date;] [Path=path]
[Domain=damain_name;] [Secure]
The above code will create a cookie named Cookie name with a value of Myfirstcookie. The parameters in square brackets [] are optional, the parameter expires domain sets the cookie expiration date, if not set, and is not manually deleted, the cookie will always be valid; path and domain together specify URL or cookie-related URLs The session keyword means that no cookie is sent in the normal HTTP sequence.
How do I use cookies in PHP?
To use cookies in PHP, you must first set up a cookie. I can set cookies manually with Setcookie ().
such as: Setcookie (string name [, string value [, int expire [, String path [, string domain [, int secure]]]);
In addition to name, the others are optional.
A simple example of setting a cookie:
Setcookie (' NAME ', ' Messi ');
Setcookie (' NAME ', ' Messi ', Time () +3600, '/web ');
The above is the content of PHP learning cookies, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!