GetCookie Method  
 

Return information about the specified cookie.

Syntax

object.GetCookie( CookieName, CookieValue, [CookiePath], [CookieDomain], [CookieExpires], [CookieFlags] )

Parameters

CookieName
A string which specifies the name of the cookie to return information about. To obtain a list of cookies which have been set by the server, use the CookieCount and CookieName properties.
CookieValue
A string which will contain the value of the cookie when the method returns. This parameter must be passed by reference.
CookiePath
An optional string argument which will contain the cookie path when the method returns. This specifies a path for the resources where the cookie should be used. For example, a path of "/" indicates that the cookie should be provided for all resources requested from the server. A path of "/data" would mean that the cookie should be included if the resource is found in the /data folder or a sub-folder, such as /data/projections.asp. However, the cookie would not be provided if the resource /info/status.asp was requested, since it is not in the /data path. The cookie should only be sent to the server if the resource being requested is located in the directory or subdirectory of this path. This parameter must be passed by reference. If this information is not required, the argument can be omitted.
CookieDomain
An optional string argument which will contain the domain that the cookie is valid for. Matches are made by comparing the name of the server against the domain name specified in the cookie. If the domain is example.com, then any server in the example.com domain would match; for example, both shipping.example.com and orders.example.com would match the domain value. However, if the cookie domain was orders.example.com, then the cookie would only be sent if the resource was requested from orders.example.com, not if the resource was located on shipping.example.com or www.example.com. This parameter must be passed by reference. If this information is not required, the argument can be omitted.
CookieExpires
An optional date value which specifies when the cookie expires and should no longer be sent to the server when requesting a resource in the path specified by the CookiePath value. This is only valid for persistent cookies, since session cookies are automatically deleted when the client application terminates. The time is always expressed as Coordinated Universal Time. This parameter must be passed by reference. If this information is not required, the argument can be omitted.
CookieFlags
An optional integer value which provides status information about the cookie. A value of zero indicates that there are no special status flags for the cookie. This parameter must be passed by reference. This argument may be omitted if the information is not required. The following values are currently defined:
Value Description
httpCookieSecure This flag specifies that the cookie should only be provided to the server if the connection is secure.
httpCookieSession This flag specifies that the cookie should only be used for the current application session and should not be stored permanently on the local system.

Return Value

This method returns a Boolean value. A value of true is returned if the cookie name is valid. Otherwise, a value of false is returned, which indicates that a cookie with that name does not exist.

Remarks

The Hypertext Transfer Protocol uses special tokens called "cookies" to maintain persistent state information between requests for a resource. These cookies are exchanged between the client and server by setting specific header fields. When a server wants the client to use a cookie, it will include a header field named Set-Cookie in the response header when the client requests a resource. The client can then take this cookie and store it, either temporarily in memory or permanently in a file on the local system. The next time that the client requests a resource from that server, it can send the cookie back to the server by setting the Cookie header field. The GetCookie method searches for a cookie set by the server in the Set-Cookie header field. The SetCookie method creates or modifies the Cookie header field for the next resource requested by the client.

There are two general types of cookies that are used by servers. Session cookies exist only for the duration of the client session; they are stored in memory and not saved in any kind of permanent storage. When the client application terminates, session cookies are deleted and no longer used. Persistent cookies are stored on the local system and are used by the client until their expiration time.

It is the responsibility of the client application to store persistent cookies and determine if a cookie meets the criteria required to be submitted to the server. If the application wishes to send the cookie, it can use the SetCookie method and specify the cookie name and value.

See Also

CookieCount Property, CookieName Property, CookieValue Property, ClearHeaders Method, SetCookie Method