473,587 Members | 2,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cookies shorter than a session?

I'm trying to set a cookie to expire 10 seconds after it is created.
However, it seems to last until I close all browser windows.

var objDate = new Date();
objDate.setSeco nds( objDate.getSeco nds() + 10 );
document.cookie = "hasSeenPopup=T RUE;";
document.cookie += "expires=" + objDate.toGMTSt ring();

I then set the cookie to expire in 1000 seconds, to test that it could
indeed last longer than a session. However, when I close all browser
windows, the cookie is gone by the time I reopen the browser, no matter
how quickly I do this.

I am doing something incorrectly?

Aug 4 '05 #1
4 1964

I think the shortest you can get is 'session', change your approach
instead. Maybe using a server session.

Danny

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Aug 5 '05 #2
2obvious <Ev************ @gmail.com> wrote in message news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I'm trying to set a cookie to expire 10 seconds after it is created.
However, it seems to last until I close all browser windows.

var objDate = new Date();
objDate.setSeco nds( objDate.getSeco nds() + 10 );
document.cookie = "hasSeenPopup=T RUE;";
document.cookie += "expires=" + objDate.toGMTSt ring();

I then set the cookie to expire in 1000 seconds, to test that it could
indeed last longer than a session. However, when I close all browser
windows, the cookie is gone by the time I reopen the browser, no matter
how quickly I do this.

I am doing something incorrectly?


It seems that a date-specified cookie can expire during a session, in as little as 10 seconds if required.

<SCRIPT type='text/javascript'>

document.write( "COOKIE DETECTED: "+ /cookieLife/.test(document. cookie) + "<BR><BR>" );

var exp=new Date(), lifeSecs=10;

document.write( "System time: "+exp+"<BR><BR> ");

exp.setSeconds( exp.getSeconds( )+lifeSecs);

document.write( "Setting expiry to system time advanced "+lifeSecs+ " secs: " + exp +
"<BR><BR> Reload page to test duration.");

document.cookie ="cookieLife=tr ue;expires="+ex p.toGMTString() ;

</SCRIPT>

--
Stephen Chalmers

547265617375726 520627572696564 206174204F2E532 E207265663A2054 51323437393134

Aug 5 '05 #3
Stephen Chalmers wrote:
2obvious <Ev************ @gmail.com> wrote in message news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I'm trying to set a cookie to expire 10 seconds after it is created.
However, it seems to last until I close all browser windows.

var objDate = new Date();
objDate.setSe conds( objDate.getSeco nds() + 10 );
document.cook ie = "hasSeenPopup=T RUE;";
document.cook ie += "expires=" + objDate.toGMTSt ring();

I then set the cookie to expire in 1000 seconds, to test that it could
indeed last longer than a session. However, when I close all browser
windows, the cookie is gone by the time I reopen the browser, no matter
how quickly I do this.

I am doing something incorrectly?

It seems that a date-specified cookie can expire during a session, in as little as 10 seconds if required.

<SCRIPT type='text/javascript'>

document.write( "COOKIE DETECTED: "+ /cookieLife/.test(document. cookie) + "<BR><BR>" );

var exp=new Date(), lifeSecs=10;

document.write( "System time: "+exp+"<BR><BR> ");

exp.setSeconds( exp.getSeconds( )+lifeSecs);

document.write( "Setting expiry to system time advanced "+lifeSecs+ " secs: " + exp +
"<BR><BR> Reload page to test duration.");

document.cookie ="cookieLife=tr ue;expires="+ex p.toGMTString() ;

</SCRIPT>


That seems to work pretty well in some browsers, but not in Safari.
Is there an open standard or official specification for working with
cookies? Below is a link to Netscape's 'specification' and a script
that works in Safari (as well as any other browser I tested):

<URL:http://wp.netscape.com/newsref/std/cookie_spec.htm l>

<URL:http://developer.apple .com/internet/safari/faq.html#anchor 6>

The Netscape link is provided in the W3C's pages on cookie handling
mechanisms, so I guess it must be as good as you'll get.

<URL:http://www.w3.org/Library/src/HTCookie.html>
--
Rob
Aug 5 '05 #4
JRS: In article <42**********@m k-nntp-2.news.uk.tisca li.com>, dated
Fri, 5 Aug 2005 02:43:59, seen in news:comp.lang. javascript, Stephen
Chalmers <ig******@lycos .co.uk> posted :

exp.setSeconds (exp.getSeconds ()+lifeSecs);


Using that purely as an illustration, since the time taken to do it once
is negligible :

K = 40000 ; D = new Date()
D1 = new Date()
J = K ; while (J--) D.setSeconds(D. getSeconds()+1)
D2 = new Date()
J = K ; while (J--) D.setUTCSeconds (D.getUTCSecond s()+1)
D3 = new Date()
J = K ; while (J--) D.setTime(D.get Time()+1000)
D4 = new Date()
J = K ; while (J--) {}
D5 = new Date()

x = [D2-D1, D3-D2, D4-D3, D5-D4]

gives 12140,1210,770, 110

The non-UTC function (no doubt because it considers local time) is about
ten times slower than the UTC function, which is about 1.7 times slower
than directly changing the value. In my system.

Javascript will look a bit odd if the M.....s manage to abolish UTC; JS
should have used GMT instead.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Aug 5 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2809
by: windandwaves | last post by:
Hi Gurus I am basically sorry that I have to bother you about this. I am a PHP beginner and I have been studying sessions and cookies over the last few weeks. I have learned lots, but I am missing the big picture. Is it like this: 1. user comes to site 2. user does something (e.g. a search) that may be useful later => session
2
3329
by: Amit D.Shinde | last post by:
Hello Experts.. I need some help regarding cookies and session objects and also global.asa file I am creating one cookie when a user logs in on my website. The cookie stores the login name of the user. I want that cookie should get deleted when user closes the browser without signing out. I think it is done in global.asa file . But i...
3
2094
by: Marcin Gorzynski | last post by:
Hi Our partner is using our page in a frame. That couses a problem because our domain is unable to issue the cookie also session does not work. each time you click in the frame new session is created. Is there any way that cookie can be issed , some way to go arround frames restrictions. Thanks for your help. Marcin Gorzynski...
7
1997
by: Marcus | last post by:
I know that when you start a session in PHP, the "cookie" it creates is not the same as those that are stored in your browser's temp folder, and instead is kept in RAM. I am confused because in every session tutorial I have ever read, the author invariably mentions the 2 main ways of propagating sessions - through cookies and appended to the...
6
6440
by: Paul | last post by:
Here is a question that should get everyone going. I have an ecommerce site where I need to pass the order_id to every page. So which method is the best practice to pass this variable between pages: Cookies or Session variable or by the HTTP header (either GET querystring or POST form)? I do not like to use sessions because they time out...
3
1609
by: Mark | last post by:
I'm told that ram based cookies refer to session cookies (which the browser may still store on disk if it likes). These cookies that are destroyed when the bowser exits. If they are "session cookies", and we have disabled the use of session because we have clustered web servers and do not want to store session state elsewhere due to...
24
2426
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How can I see in javascript if a web browser accepts cookies? ----------------------------------------------------------------------- Writing a cookie, reading it back and checking if it's the same. http://www.w3schools.com/js/js_cookies.asp Additional...
5
5556
by: jheines | last post by:
I am trying to explain how cookies and sessions work in a class I teach, but I have hit a wall when it comes to the interaction between cookies and the state of the privacy settings in Internet Explorer. I would appreciate any help anyone can offer, please. First, consider the following very simple JavaScript function: function...
2
4998
by: StanB | last post by:
I came across this weird problem: 1. Session state stops working after the app is deployed to another server because IE does not accept cookies. 2. It works if cookieless="true" in the web.config 3. Yes, I tried IE - Tools - Privacy - Accept All Cookies and also Override automatic cookie handling, Always allow session cookes
0
7918
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.