Set Cookie Parameters

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

Explanation

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.

Name=Value:
This sets both the cookie's name and its value.

Example:

username=john
Expire=Date:
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.

Example:

expires=02/02/2010 00:00:00
Path=Path:
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.

Example:

path=/hscripts/tutorials
Domain=Domain:
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 (.domain.com). 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.

Example:

domain=tofocus.info
Secure:
This optional flag indicates that the browser should use SSL when sending the cookie to the server. This flag is rarely used.

Example:

secure

These are the parameters to be checked to set cookie.

Ask Questions

Ask Question