VB icon

Detect if Cookies are Enabled with 1 (that's one!) line of code

Email
Submitted on: 1/5/2015 10:47:00 AM
By: Jeff Allen (from psc cd)  
Level: Beginner
User Rating: By 6 Users
Compatibility: ASP (Active Server Pages), VbScript (browser/client side)
Views: 1879
 
     In looking for an easy way to detect the client browser's cookie settings, everything I've found has been complex. Each example I've found requires a page refresh or redirect to itself. This severely hampers true application development as the Request.Form collection is then cleared. This code is something simple I stumbled on and it works (see explanations).
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Detect if Cookies are Enabled with 1 (that's one!) line of code
' Description:In looking for an easy way to detect the client browser's cookie settings, everything I've found has been complex. Each example I've found requires a page refresh or redirect to itself. This severely hampers true application development as the Request.Form collection is then cleared. This code is something simple I stumbled on and it works (see explanations).
' By: Jeff Allen (from psc cd)
'
' Assumes:I have NOT tested this on ALL platforms or with all clients, however, since the SITESERVER/ID cookie key links the client to a session established on the server, I'm fairly certain it will work for all cases. Please don't shoot me if it doesn't. :) I DO know that it works on Microsoft IIS and with IE v5 or better. I included in my example a redirect to an error page, however you could do absolutely anything you wanted if the test was true.
'**************************************

<%@ Language=VBScript %>
<%option explicit
If Len(Request.Cookies("SITESERVER")("ID")) = 0 Then Response.Redirect "BrowserError.asp"
%>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.