The Cookies collection is used to set or get cookie values. If the cookie does not exist, it will be created, and take the value that is specified.
Note: The Response.Cookies command must appear before the <html> tag.
|name||Required. The name of the cookie|
|value||Required for the Response.Cookies command. The value of the cookie|
|attribute|| Optional. Specifies information about the cookie. Can be one of the following parameters:
|key||Optional. Specifies the key to where the value is assigned|
The "Response.Cookies" command is used to create a cookie or to set a cookie value:
In the code above, we have created a cookie named "firstname" and assigned the value "Alex" to it.
It is also possible to assign some attributes to a cookie, like setting a date when a cookie should expire:
Now the cookie named "firstname" has the value of "Alex", and it will expire from the user's computer at May 10, 2002.
The "Request.Cookies" command is used to get a cookie value.
In the example below, we retrieve the value of the cookie "firstname" and display it on a page:
A cookie can also contain a collection of multiple values. We say that the cookie has Keys.
In the example below, we will create a cookie-collection named "user". The "user" cookie has Keys that contains information about a user:
The code below reads all the cookies your server has sent to a user. Note that the code checks if a cookie has Keys with the HasKeys property:
The perfect solution for professionals who need to balance work, family, and career building.
More than 10 000 certificates already issued!
The HTML Certificate documents your knowledge of HTML.
The HTML5 Certificate documents your knowledge of advanced HTML5.
The CSS Certificate documents your knowledge of advanced CSS.
The jQuery Certificate documents your knowledge of jQuery.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
Your message has been sent to W3Schools.