Cookies are often used to identify users. Cookie is a small file that the server stays on the user's computer. Each time a computer requests a page through a browser, the computer sends a cookie.
Cookies are not stored on the server, but stored in the user's browser. This also brings security considerations. For some general security applications, you can use them with little encryption.
The "response. Cookies" command is used to create a cookie, create a cookie named "firstname", and assign it "Alex ":
<% Response. Cookies ("firstname") = "Alex" %>
It is also possible to allocate attributes to cookies, such as setting the cookie expiration time:
<% Response. Cookies ("firstname") = "Alex" response. Cookies ("firstname"). expires = # May 10, 2002 # %>
The "request. Cookies" command is used to retrieve the cookie value:
<% Fname = request. Cookies ("firstname") response. Write ("firstname =" & fname) %>
Output:
Firstname = Alex
If a cookie contains a set of multiple values, we can say that the cookie has a key (KEYS ).
In the following example, we will create a cookie set named "user. "User" cookies have keys that contain user information:
<% Response. cookies ("user") ("firstname") = "John" response. cookies ("user") ("lastname") = "Adams" response. cookies ("user") ("country") = "UK" response. cookies ("user") ("Age") = "25 "%>
We will also encounter browsers that do not support cookies. In this way, we can only use other methods to implement cookie functions, such as URL-based value passing or form-based value passing, although this is clumsy.