CookiesEnabled Property

 

Type: Boolean

 

Returns True if the visitor has their cookies enabled, False if their cookies have been disabled.

 

Note: You must call the GetExtPropertiesEx method before checking the value of this property. This property requires either the Professional or Enterprise Edition of BrowserHawk.

 

Tip: See the cookies.asp file in your BrowserHawk installation directory for a detailed example on detecting disabled cookies.

Session Vs. Persistent cookies with IE 5.0 and higher

For users with IE 5.0 and higher, BrowserHawk can also detect the difference between disabled session cookies Vs. disabled persistent cookies. Session cookies are cookies that are destroyed when the browser is closed. Persistent cookies are cookies that are stored on the user’s machine for a period of time as set by the cookie.

 

To check for disabled session cookies, pass in "cookie_sess" to SetExtProperties prior to calling GetExtPropertiesEx. If the user has session cookies disabled, the CookiesEnabled property will be set to False regardless of whether persistent cookies are enabled.

 

To check for disabled persistent cookies, pass in "cookie_perm" to SetExtProperties prior to calling GetExtPropertiesEx. If the user has persistent cookies disabled, the CookiesEnabled property will be set to False regardless of whether session cookies are enabled.

 

To check for both disabled session and persistent cookies, pass in "cookie_sess, cookie_perm" to SetExtProperties, or "cookie_both", prior to calling GetExtPropertiesEx. If the user has either session or persistent cookies disabled (or both types are disabled), the CookiesEnabled property will be set to False. If you asked BrowserHawk to check for both disabled session and persistent cookies, and CookiesEnabled is returned as False, you can determine the reason why they failed the cookie test by checking the value of the cookieCheckType property as follows:

 1 = persistent cookies are disabled

 2 = session cookies are disabled

 3 = both permanent and session cookies are disabled

Cookie detection for non-IE 5.0 and higher

With IE versions prior to 5.0, and any version of Netscape and Opera browsers, there is no difference between disabled session Vs. persistent cookies. This is because IE 5.0 and higher are the only browsers that allow enabled/disabled status to be set differently for each cookie type. Therefore it is irrelevant whether you pass in "cookie_sess" or "cookie_perm" for this check (or "cookie_both") because BrowserHawk will check the browser the same way. In this case all the various cookie check options are synonymous.

Examples

 

Example 1:

This code snippet enforces that any IE 5+ has both session and persistent cookies enabled, and any non-IE 5+ browser (such as IE 4.01 or any Netscape/Opera browser) has cookies enabled (these browser do not allow session and persistent cookies to be disabled separately). If cookies are not enabled the user is redirected to a nocookies.asp page.

 

<% set bhObj = Server.CreateObject("cyScape.browserObj")

bhObj.SetExtProperties "cookie_both"

bhObj.GetExtPropertiesEx

if bhObj.CookiesEnabled = False then

response.redirect "/nocookies.asp"

end if %>

<html> … content for users with cookies enabled goes here … </html>

 

Example 2:

This code snippet enforces that any IE 5+ has session cookies enabled (regardless of whether persistent cookies are enabled), and any non-IE 5+ browser (such as IE 4.01 or any Netscape/Opera browser) has cookies enabled. If cookies are not enabled the user is redirected to a nocookies.asp page.

 

<% set bhObj = Server.CreateObject("cyScape.browserObj")

bhObj.SetExtProperties "cookie_sess"

bhObj.GetExtPropertiesEx

if bhObj.CookiesEnabled = False then

response.redirect "/nocookies.asp"

end if %>

<html> … content for users with cookies enabled goes here … </html>

 

Example 3:

This code snippet enforces that any IE 5+ has persistent cookies enabled (regardless of whether session cookies are enabled), and any non-IE 5+ browser (such as IE 4.01 or any Netscape/Opera browser) has cookies enabled. If cookies are not enabled the user is redirected to a nocookies.asp page.

 

<% set bhObj = Server.CreateObject("cyScape.browserObj")

bhObj.SetExtProperties "cookie_perm"

bhObj.GetExtPropertiesEx

if bhObj.CookiesEnabled = False then

response.redirect "/nocookies.asp"

end if %>

<html> … content for users with cookies enabled goes here … </html>

 

Tip: When testing for both disabled session and persistent cookies, you can use the CookieCheckType property to determine why a user failed the cookie test (for example, session cookies were enabled but persistent cookies were not, etc.).

 

Special notes for this property:

 

See Also:

WebStorageEnabled Property

Cookies Property

CookieCheckType Property

GetExtPropertiesEx Method

SetExtProperties Method

CookieDuration Property