Forum Moderators: coopster

Message Too Old, No Replies

Determine if browser is cookie-enabled

In one pageload

         

MatthewHSE

12:05 pm on May 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Take a hypothetical situation (yeah, right!) where you have to find out if a visitor's browser accepts cookies or not, and display different data accordingly - and you only have one pageload to do it in. Can this be done, and if so, how?

I've thought of several possible solutions, including creative uses of header('Location...') redirects, but so far haven't found anything that works. If anyone else knows how to do this, I would find it very useful in my particular "hypothetical situation!" ;)

milanmk

1:21 pm on May 10, 2006 (gmt 0)

10+ Year Member



To properly detect if a cookie is being accepted via the server, the cookie needs to be set on one HTTP request and read back in another. This cannot be done in single request.

If you use client-side languages to set a cookie, you can set and read on the same page. Cookies set by JavaScript reside in the browser's memory so you will know if they have been accepted or not. Check by setting a test value, and then try to read that value back out of the cookie. If the value still exists, the cookie was accepted.

Milan