Cookie法,Cookie设置&吸气剂 [英] Cookie Law, Cookie setter & getter
问题描述
我目前正在为几个网站编写自定义Cookie法解决方案。我试图使解决方案/插件尽可能多的一体化解决方案尽可能的代码作为脚本的第一位。目前我几乎做了一切,一切看起来很漂亮,我想给用户接受或否认拒绝不只是重定向他们,但仍然允许他们使用网站的能力。
I am currently coding a custom cookie law solution for several websites. I am trying to make the solution/plugin as much of an "all in one solution" as possible with the code being included as the first bit of script. currently I have almost done everything and it all looks very pretty, I want to give the user the ability to "accept" or "deny" with deny not just redirecting them away but still allowing them to use the website.
到目前为止,我有一个正确设置为接受和拒绝的cookie,它在cookie中设置一个true或false值,根据选择接受或拒绝。
So far I have a cookie being set correctly for accept and deny which either sets a true or false value in a cookie based on there choice accept or deny.
我想在if语句中使用我找到的用于重新定义cookie setter和getter的代码,以防止在用户没有给出
I would like to use the code I have found for redefining the cookie setter and getter, in a if statement to prevent cookies from being set if the user has either not given a permission or not selected an answer yet.
document.__defineGetter__("cookie", function() { return '';} );
document.__defineSetter__("cookie", function() {} );
到目前为止,我有这个代码来检查用户是否允许cookie,
So far I have this code to check if the user has allowed cookies,
if(checkCookie != true){
// Run code to redefine cookie setter getter to prevent cookies from being set
}else{
// Don't do anything and the cookies should be run as usual.
};
有人可以告诉我或指示我朝着正确的方向使用cookie setter和getter正如我已经解释过的那样。
Could someone enlighten me or point me in the right direction on how to use cookie setter and getter to do as I have explained?
推荐答案
作为Alex Wayne对你的问题的评论,cookies设置之前,你甚至看到<$
as Alex Wayne stated as comment to your question, cookies are set before you even see the <html>
tag coming into your browser.
http如下所示:
HTTP/1.1 200 OK
Server: Nginx
Content-Length: x (size of the following content)
Content-Type: text/html (this is what identifies it as html)
Set-Cookie: foo=bar; expires=Tue, 4-Dec-2012 19:30:42 GMT; Max-Age=2592000; Path=/; Version="1"
<!DOCTYPE html>
<html>
...
你可以做什么,必须做的是执行这样的动作设置一个不跟踪我的会话cookie,告诉服务器不要将任何cookie放在提供的请求上。
what you could do, and must do to perform such an action is to set a "do not track me" session cookie that tells the server to not put any cookies onto the served requests.
另一种方式可能是获取变量该地址栏通知服务器不设置跟踪Cookie。
another way could be to have a get variable in the address bar that tells the server to not set track cookies.
实际上是什么cookie。
thats what cookies are for actually.
这篇关于Cookie法,Cookie设置&吸气剂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!