Set Cookie Parameters

What are elements does the cookie parameter consists?
How to Set Cookie Parameters?


Cookie consists of 6 parameters that can be passed to it. They are:
Syntax:setCookie(cookieName, cookieValue[, expire[, path[, domain[, isSecure]]]] )
* The name of the cookie,
* The expiration date of the cookie,
* The path the cookie is valid for,
* The domain the cookie is valid for,
* The need for a secure connection to exist to use the cookie.

This sets both the cookie's name and its value.


This optional value sets the date that the cookie will expire on. The date should be in the format returned by the toGMTString() method of the Date object. If the expire value is not given, the cookie will be destroyed the moment the browser is closed.


expires=02/02/2010 00:00:00
This optional value specifies a path within the site to which the cookie applies. Only documents in this path will be able to retrieve the cookie. Usually this is left blank, meaning that only the path that set the cookie can retrieve it.


The domain parameter is used to set the domain the cookie is accessable to. A path can be set for your own domain only and the domain path must include at least two periods ( It must match your server's domain name. Therefore cookies are not a security risk since only the server that sets them can use them.

This optional flag indicates that the browser should use SSL when sending the cookie to the server. This flag is rarely used.



These are the parameters to be checked to set cookie.

Ask Questions

Ask Question