[Zope] Checking if cookies enabled

Richard Barrett R.Barrett@ftel.co.uk
Thu, 22 Nov 2001 17:18:50 +0000


At 11:02 22/11/2001 -0500, Edmund Goppelt wrote:
>How does one check if a user has disabled cookies on his browser?
>
>--
>
>Ed Goppelt

You cannot interrogate a browser to determine if it accepts and processes 
HTTP Cookie headers; HTTP only lets servers respond to browser requests.

However, judicious use of Javascript can help you. Send a response which 
has the Cookie setting header in it which when received immediately gets 
the browser to reload another of your URLs where you can test if the 
browser has included the cookie. For instance if your page, say 
setcookie.html, contained the following HTML (note < and > translated to 
&lt; and &gt; to avoid misinterpretation of the HTML by MUAs) :

&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;SCRIPT LANGUAGE="Javascript"&gt;
&lt;!--
     location="./cookietest.html";
--&gt;
&lt;/SCRIPT&gt;
&lt;p&gt;
You appear to have Javascript disabled, please &lt;a 
href="./cookietest.html"&gt;click here&lt;/a&gt; to confirm.
&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;

The browser should immediately request the second page, cookietest.html, 
and you should be able to test for the presence of the Cookie. If it 
doesn't show up then you can assume Cookies are either disabled in or not 
supported by the browser and you can respond as appropriate to the user.

Of course, this assumes that the user hasn't also disabled Javascript, in 
which case you'll have to rely on them clicking on the link to request the 
second page and complete the test.