Example of Cookies In ASP
Asp / / July 04, 2021
A cookie it is generally used to identify a user. A cookie It is a small file that the server saves on the user's computer. Every time the same computer requests a page with the browser, it will send the cookie also. With ASP, you can create and read the values of cookies.
How to create a cookie?
The command to create cookies is "Response. Cookies"
Note: The command "Response. Cookies "must appear BEFORE the tag .
In the example below, we will create a cookie called "name" and assign the value "Luffy" to it:
Code:Response. Cookies ("name") = "Luffy"
%>
It is also possible to assign properties to the cookie, such as the expiration date of the cookie. For example:
Code:Response. Cookies ("name") = "Luffy"
Response. Cookies ("name"). Expires = # May 25, 2009 #
%>
This code will make the cookie expire on May 25, 2009.
How to read a cookie?
The same command "Response. Cookies "is the one used to read the values of a cookie.
Example of reading a cookie in ASP
Code:firstname = Response. Cookies ("name")
response.write ("Name =" & firstname)
%>
This code will show the value of the cookie name.