如何检测服务器端是否禁用Cookie [英] How to detect server-side whether cookies are disabled

查看:154
本文介绍了如何检测服务器端是否禁用Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在服务器(服务器端)上检测浏览器中的Cookie是否已禁用?可能吗?

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

详细说明:我正在处理服务器上的HTTP请求。我想通过 Set-Cookie 头设置一个cookie。我需要知道cookie是否将由客户端浏览器设置,否则我的设置cookie的请求将被忽略。

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.

推荐答案

使用设置的Cookie发送重定向响应;当处理(特殊)重定向网址测试的cookie - 如果它有重定向到正常处理,否则重定向到错误状态。

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.

注意,这只能告诉你浏览器允许设置cookie,但不允许设置多长时间。我的FF允许我强制所有的cookies为会话模式,除非网站被特别添加到一个例外列表 - 当FF关闭时,不管服务器指定的过期,这样的cookie会被丢弃。这是我总是运行FF的模式。

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.

这篇关于如何检测服务器端是否禁用Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆