这不是“设定”的。一个cookie到期 - 为什么? [英] This doesn't "set" a cookie to expire - why?

查看:79
本文介绍了这不是“设定”的。一个cookie到期 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//从 http://www.javascripter.net/faq获取/settinga.htm


//请注意,如果您将日期设置为-1,那么COOKIE将被设置为昨天

和THUS EXPIRE

函数setCookie(name,value,days,docObj){

var today = new Date();

var expire = new Date() ;

if(days == null || isNaN(days)|| days == 0)days = 1;

if(days> = 1 || days < 0)expire.setTime(today.getTime()+ 3600000 *

24 *天);

docObj.cookie = name +''=''+ escape (值)+''; expires =''+

expire.toGMTString();

}

我正在使用这个Javascript函数来设置一个cookie到期,然而,

由于某些原因,当我设置它到期时:


setCookie(''my_cookie'','' '',-1,this.document);


它设置名为my_cookie的cookie。到字面''''没有实际到期但是仍然存在'''',即使在页面上也是存在的'''
重新加载!


我正在使用Netscape 7.1和IE 5.1并且两者都发生了


我想在页面重新加载时完全销毁cookie,这是什么
我必须支付
吗?


Thanx

菲尔

解决方案

Phil Powell于2006年2月8日在comp.lang.javascript中写道

我希望在页面重新加载时完全销毁cookie,我必须做什么?




然后不要首先设置cookie?


-

Evertjan。

荷兰。

(请在我的电子邮件地址中将x'变为点数)


这不是一个选择。退出应用程序后,cookie必须被销毁,以便重定向将您带回登录页面

页面。处理服务器端的cookie破坏,但我认为不是很有效。$ / b

Phil


Evertjan。写道:

Phil Powell于2006年2月8日在comp.lang.javascript写了

我希望cookie完全在页面重新加载时销毁,我必须做什么?



然后不要首先设置cookie?

-
Evertjan。
荷兰。
(请将x''es改为我的电子邮件地址中的点)




Phil Powell于2006年2月8日在comp.lang.javascript中写道


菲尔

Evertjan。写道:

Phil Powell于2006年2月8日在comp.lang.javascript中写道

>我想在页面重新加载时完全破坏cookie,
>我必须这样做吗?
>
然后不要在第一时间设置cookie?




[请不要toppost在usenet上]

这不是一个选择。


难道你不能将它的价值改为无害的东西吗?

退出申请后,必须将cookie销毁订购重定向带你回到登录页面。处理服务器端的cookie破坏,但我认为不是很有效。




等等,您使用的是服务器端代码吗?

然后使用会话变量更容易,更安全。

即使整个会话都可以销毁,删除所有会话变量

作为完美的注销措施。


ASP:session.abandon

PHP:???


-

Evertjan。

荷兰。

(请在我的电子邮件地址中将x'变为点数)


// OBTAINED FROM http://www.javascripter.net/faq/settinga.htm

// NOTE THAT IF YOU SET days TO -1 THE COOKIE WILL BE SET TO YESTERDAY
AND THUS EXPIRE
function setCookie(name, value, days, docObj) {
var today = new Date();
var expire = new Date();
if (days == null || isNaN(days) || days == 0) days = 1;
if (days >= 1 || days < 0) expire.setTime(today.getTime() + 3600000 *
24 * days);
docObj.cookie = name + ''='' + escape(value) + '';expires='' +
expire.toGMTString();
}
I am using this Javascript function to set a cookie to expire, and yet,
for some reason, when i set it to expire:

setCookie(''my_cookie'', '''', -1, this.document);

It sets the cookie named "my_cookie" to the literal '''' which does not
actually expire but still exist with the value of '''', even upon page
reload!

I''m using Netscape 7.1 and IE 5.1 and happens on both

I want the cookie to be completely destroyed upon page reload, what
must I do?

Thanx
Phil

解决方案

Phil Powell wrote on 08 feb 2006 in comp.lang.javascript:

I want the cookie to be completely destroyed upon page reload, what
must I do?



Then do not set the cookie in the first place?

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


That is not an option. Upon quitting the application the cookie must
be destroyed in order for redirection to take you back to the login
page. Server-side cookie destruction is handled but I believe not very
effectively.

Phil

Evertjan. wrote:

Phil Powell wrote on 08 feb 2006 in comp.lang.javascript:

I want the cookie to be completely destroyed upon page reload, what
must I do?



Then do not set the cookie in the first place?

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)




Phil Powell wrote on 08 feb 2006 in comp.lang.javascript:


Phil

Evertjan. wrote:

Phil Powell wrote on 08 feb 2006 in comp.lang.javascript:

> I want the cookie to be completely destroyed upon page reload, what
> must I do?
>
Then do not set the cookie in the first place?



[please do not toppost on usenet]
That is not an option.
Cann''t you just change it''s value to something inoffensive?
Upon quitting the application the cookie must
be destroyed in order for redirection to take you back to the login
page. Server-side cookie destruction is handled but I believe not very
effectively.



Oh wait, you are using serverside code?

Then it is much easier and safer to use session variables.
Even the whole session can be destroyed, deleting all session variables
as a perfect logout measure.

ASP: session.abandon
PHP: ???

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


这篇关于这不是“设定”的。一个cookie到期 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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