How to detect server-side whether cookies are disabled

Alexander Yanovets picture Alexander Yanovets · Feb 10, 2009 · Viewed 89.3k times · Source

How can I detect on the server (server-side) whether cookies in the browser are disabled? Is it possible?

Detailed explanation: I am processing an HTTP request on the server. I want to set a cookie via the Set-Cookie header. I need to know at that time whether the cookie will be set by the client browser or my request to set the cookie will be ignored.

Answer

Lawrence Dol picture Lawrence Dol · Feb 10, 2009

Send a redirect response with the cookie set; when processing the (special) redirected URL test for the cookie - if it's there redirect to normal processing, otherwise redirect to an error state.

Note that this can only tell you the browser permitted the cookie to be set, but not for how long. My FF allows me to force all cookies to "session" mode, unless the site is specifically added to an exception list - such cookies will be discarded when FF shuts down regardless of the server specified expiry. And this is the mode I run FF in always.