Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect server-side whether cookies are disabled

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.

like image 578
Oleksandr Yanovets Avatar asked Feb 10 '09 07:02

Oleksandr Yanovets


People also ask

Are cookies accessible on server side?

cookies are always client-side. Session cookies are stored on the client machine and at a minimum contain a reference to the session Id. If a server has a cookie it's because it's acting as a client. You can add cookies with JavaScript or from the server, that's probably what they mean by client vs server cookies.

How do I find cookies on my server?

web servers instruct the client to store a cookie by issuing a special HTTP header, "Set-Cookie". once cookied, every subsequent request by the client to that server will include the HTTP header, "Cookie" with the data that was stored. by default, cookies are deleted when the user quits the browser.


1 Answers

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.

like image 56
Lawrence Dol Avatar answered Nov 11 '22 18:11

Lawrence Dol