473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Can't set session cookie???

I'd like to set a session cookie that expires once the browser is
closed. I've tried:

document.cookie = "wm_javascript=" + escape("SomeName|" +
window.document.referrer);

with no expires. This doesn't set a cookie. It seems I must put in
an expiration for the cookie to set. The code below does work:

var the_name = window.document.referrer;
var the_cookie = "wm_javascript=" + escape("SomeName|" + the_name);
var the_date = new Date("December 31, 2050");
var the_cookie_date = the_date.toGMTString();
the_cookie = the_cookie + ";expires=" + the_date.toGMTString();
document.cookie = the_cookie;

Why doesn't the session cookie set? I'm using IE6.

Also, if a user has multiple IE windows open, will the session cookie
expires only after all IE windows have closed?

Thanks,
Brett
Jul 23 '05 #1
3 6357
Brett wrote:
document.cookie = "wm_javascript=" + escape("SomeName|" +
window.document.referrer);
with no expires. This doesn't set a cookie. It seems I must put in
an expiration for the cookie to set. The code below does work:

var the_name = window.document.referrer;
document.referrer is unreliable and using it is error-prone.
var the_cookie = "wm_javascript=" + escape("SomeName|" + the_name);
var the_date = new Date("December 31, 2050");
Using date strings is error-prone because interpretation is
implementation-dependent. Use several arguments instead:

var the_date = new Date(2050, 11, 31);
var the_cookie_date = the_date.toGMTString();
the_cookie = the_cookie + ";expires=" + the_date.toGMTString();
document.cookie = the_cookie;

Why doesn't the session cookie set? I'm using IE6.
Implementations usually follow the Netscape cookie specification:

<http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/cookies.html#1002170>

Some UAs set cookies only if set by a resource retrieved via HTTP, thus
they do not set it with documents accessed with "file:" URIs, for example.
Some UAs consider cookies without "domain=" invalid and will not set those.
Also, if a user has multiple IE windows open, will the session cookie
expires only after all IE windows have closed?


Possibly.
PointedEars
Jul 23 '05 #2
In article <c0**************************@posting.google.com >,
ac*****@cygen.com (Brett) wrote:
I'd like to set a session cookie that expires once the browser is
closed. I've tried:

Why doesn't the session cookie set? I'm using IE6.


I found it best to always set the date and time in IE. Figure out how
long you need to use the cookie and add a reasonable about of extra time
like an hour.

Has anyone gotten sessions cookies to work in IE: that is a cookie set
in IE without the date/time?

Robert
Jul 23 '05 #3
JRS: In article <41**************@PointedEars.de>, dated Wed, 28 Jul
2004 05:00:01, seen in news:comp.lang.javascript, Thomas 'PointedEars'
Lahn <Po*********@nurfuerspam.de> posted :
var the_cookie = "wm_javascript=" + escape("SomeName|" + the_name);
var the_date = new Date("December 31, 2050");


Using date strings is error-prone because interpretation is
implementation-dependent. Use several arguments instead:

var the_date = new Date(2050, 11, 31);


Which browsers do not understand new Date("December 31, 2050"); ?

It is non-ISO numeric date strings that are unreliable; but "2050/12/31"
should be safe everywhere, and is understandable by anybody; whereas
some people think that December needs a Zed, or possibly a Zee, or
transpose letters in it.

In this case, "01/01/2051" could have been used.

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

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

Similar topics

7
by: Henry Hartley | last post by:
I've got a PHP system working on a development server (Windows 2000/IIS5/PHP 4.3.3) but it doesn't seem to be working quite right on the testing server (same except PHP 4.2.3). I upgraded the PHP...
5
by: Yossi | last post by:
I want to set the asp session id path property. how can I do that? I mean, asp session id is stored in a cookie and like any other cookie it should have properties (or attributes), how can I...
1
by: Jenn | last post by:
I have done alot of web work in all sorts of languages but I have never used the simple cookie. Question is How does one set and retrieve a simple session cookie. All it will do is have an image...
1
by: Steve Remer | last post by:
My application (relevant code snippets below) originally used Session variables in order to maintain state from page to page. After being unable to solve the mystery of why those variables were...
4
by: Chris | last post by:
When a request comes into a page on my ASP.net site and a session is not found, I want to detect whether the request is an initial request or if the user did have a session going that has now been...
1
by: Daniel Michaeloff | last post by:
Hi all, I have an application that when finished redirects to a non-ASP.NET app which is choking on a huge ASP.NET session cookie. The cookie "ASP.NET_SessionId" gets transmitted by the browser...
4
by: Ibrahim. | last post by:
Hi, Kindly clarify the followings; 1. Is the session cookie & FormsAuthenticationTicket cookie Interdependent? 2. When a new SessionID is generated, I have noticed the Session Cookie and...
7
by: Victor | last post by:
I've got two domain names sharing the same IP address that use ASP VBScript If I set a session variable with domain 1, it is only available for domain 1 - this is correct? If I set an...
4
by: rgparkins | last post by:
Hello I am running out of time with a problem I have running PHP 5.04 and Apache 2.0 and really need help :(. I have a page that stores a variable in session but each time I reload that page the...
6
by: =?Utf-8?B?S2VsbHk=?= | last post by:
We just switched our web application from .NET 1.1 to 2. Once client can't login out of several that have been successful. They enter a correct user name and password, click the login button and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.