RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Our Top 10 Tips for Classic ASP : Page 5

Tidy up your server-side programming techniques with these 10 great tricks for classic ASP.

Beating the Cookie Monster

So you've found that your user has disabled cookies? He may not trust you, but if he can be sneaky, so can you. Use this technique to find out if the user has disabled cookies, and to politely tell him to turn it back on if he wants to use all the functionality on your site.

How do I find out if a user has disabled cookies?

To find out if a user has disabled cookies, follow these steps:

  1. Set a cookie.
  2. Redirect to your own page.
  3. In the redirect, read the cookie.
  4. If your cookie has a value, user has enabled cookies. If there is no value, then the user has disabled cookies.
  5. 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.
& "?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

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date