How do I find out if a user has disabled cookies?
To find out if a user has disabled cookies, follow these steps:
- Set a cookie.
- Redirect to your own page.
- In the redirect, read the cookie.
- If your cookie has a value, user has enabled cookies. If there is no value, then the user has disabled cookies.
- Use the Querystring to determine if you are on step 1 or step 3.
To set the cookie, use the following code:
Dim strCookie, strTry strCookie = Request.Cookies("MyCookie") strTry = Request.QueryString("Try") If strCookie = "" Then ' Check to see if this is a redirect ' after setting the cookie If strTry = "" Then Response.Cookies("MyCookie") = "Set" ' Redirect to this page and try again. Response.Redirect(Request.ServerVariables("SCRIPT_NAME")
& "?Try=Yes") Else ' User/Browser didn't accept cookies ' Do something... End If Else ' -- Hooray! User is accepting cookies ' -- Delete our cookie: by setting its ' -- expiry date to waaaay back Response.Cookies("MyCookie").Expires = "January 1, 1980" ' Do something... End If