473,387 Members | 1,891 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,387 software developers and data experts.

Cookie writing confusion

Hello,

Please help.

I keep data in several session variables, one of which is a complex
object tied to a custom DLL I wrote. Everything seems to be running
fine until I introduced a system to remember certain data to cookies.

At some point in my application the following code is executed

WriteCookie(key, value, new Date(((new Date()).getTime() +
(365*86400000))), "/")

Almost immediately after, the session variable holding the complex
object no longer exists (vartype of object = 0). I commented out that
line in the app and the session variable continues to exist.

I am not sure how the session variable and my writing of the cookie is
inter-related. Can someone please explain to me what might be
happening, why and how I can deal with it ?

Thank you,
Charly
Jul 23 '05 #1
5 1231
In article <30*************************@posting.google.com> ,
wa********@aol.com enlightened us with...

At some point in my application the following code is executed

WriteCookie(key, value, new Date(((new Date()).getTime() +
(365*86400000))), "/")


Sessions often store a unique ID on the client computer as a cookie
(some use URL rewriting), which the server uses to look up data with
each request. I suspect a problem with the interaction between the
session cookie and the one you are writing.
What exactly does WriteCookie look like? Got code?
--
--
~kaeli~
A man's home is his castle..., in a manor of speaking.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
Thank you for your reply.

I presumed as much since I do see a stub of something when I open the
cookie in a text editor.

The cookie writing code is as follows and is nothing out of the
ordinary, I think:

function WriteCookie(sName, sValue, dExpires, sPath, sDomain, bSecure) {
var sCookie;
var sError;

sCookie = sError = "";
if(sError.length == 0){
sCookie += escape(sName) + "=";
sCookie += escape(sValue);
if(dExpires)sCookie += "; expires=" + dExpires.toGMTString();
if(sPath) sCookie += "; path=" + sPath;
if(sDomain) sCookie += "; domain=" + sDomain;
if(bSecure) sCookie += "; secure=" + bSecure.toString();

document.cookie = sCookie;

if(sValue != GetCookie(sName)) sError = sError + "Write failure/n";
}
return sError;
}

Regards,
Charly


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
In article <40*********************@news.frii.net>, wa********@aol.com
enlightened us with...
Thank you for your reply.

I presumed as much since I do see a stub of something when I open the
cookie in a text editor.
What name are you calling it?
Have you tried calling it something else?

The cookie writing code is as follows and is nothing out of the
ordinary, I think:

function WriteCookie(sName, sValue, dExpires, sPath, sDomain, bSecure) {
var sCookie;
var sError;

sCookie = sError = "";
if(sError.length == 0){
This will always be true, since you just set it to the empty string,
above. What's the point?
sCookie += escape(sName) + "=";
sCookie += escape(sValue);
if(dExpires)sCookie += "; expires=" + dExpires.toGMTString();
Is this a copy/paste error? There may need to be a space after that
close parens.
if(sPath) sCookie += "; path=" + sPath;
if(sDomain) sCookie += "; domain=" + sDomain;
if(bSecure) sCookie += "; secure=" + bSecure.toString();

document.cookie = sCookie;


Whoops. You just wiped out the previous value of document.cookie. Bad
kitty.

document.cookie += sCookie.
That was probably your problem.

--
--
~kaeli~
Jesus saves, Allah protects, and Cthulhu thinks you'd make
a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #4
On Mon, 19 Apr 2004 12:31:29 -0500, kaeli <ti******@NOSPAM.comcast.net>
wrote:
In article <40*********************@news.frii.net>, wa********@aol.com
enlightened us with...


[snip]
if(dExpires)sCookie += "; expires=" + dExpires.toGMTString();


Is this a copy/paste error? There may need to be a space after that
close parens.


That shouldn't matter. It would be more readable, though.
if(bSecure) sCookie += "; secure=" + bSecure.toString();


This is actually incorrect. The "secure" field is a boolean in itself. If
it is present, the cookie should be made secure. If it is absent, the
cookie can be stored unaltered. Change it to

if( bSecure ) sCookie += '; secure';

From the OP:

WriteCookie(
key,
value,
new Date(((new Date()).getTime() + (365*86400000))),
"/" );

It's probably better to take advantage of Date()'s ability to roll over
automatically:

var nextYear = new Date();
nextYear.setFullYear( nextYear.getFullYear() + 1 );

WriteCookie(
key,
value,
nextYear,
"/" );

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #5
Thank you Kaeli and Michael !!

I was thinking of cookie arcania and my problem seemed to be application
of syntax.

Of course, your suggestions did the trick. And I did learn enough to
actually remember some.

Thanks again,
Charly

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #6

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

Similar topics

1
by: changed | last post by:
I'm having an inconsistent problem involving cookies. I have attempted to duplicate the OS/browser settings for the remote users in question but I cannot seem to duplicate the problem in any OS...
2
by: Syed Ghayas | last post by:
Hi, I've been having problem writing a cookie. Everything goes ok but when I supply the .Path property to "/" It just write the cookie when there is no cookie present, but when I try to update the...
5
by: brettr | last post by:
When I reference document.cookie, there is a long string of key=value; pairs listed. I may have 100 hundred cookies on my hard drive. However, most only have one key=value pair. Does the...
0
by: Nicolas Joly | last post by:
Hello, I have this (a cookie writer) <script runat="server"> void WriteClicked(Object Sender, EventArgs e) { //Create a new cookie, passing the name into the constructor HttpCookie cookie =...
2
by: venkat | last post by:
hi If you close the browser directly then the cookie won't get deleted. When ever you log off only it will get deleted. If you close the browser directly and again the open the browser for the...
2
by: Bill Borg | last post by:
Hello all, I am working on forms authentication and trying to understand: what's the relationship between the cookie expiration and the ticket expiration? I create a cookie and I add an...
10
by: DoomedLung | last post by:
Hey, I recently bought "The Javascript and DHTML Cookbook" by Danny Goodman. I'm at Chapter 1, part 1.9 "Reading and Writing Strings for Cookies" and was just interested in a utility function...
5
by: sophie_newbie | last post by:
Does anyone know how to do this? I can't seem to make it work. I'm using: c = Cookie.SimpleCookie() c = "unamepwordwhatever" c.expires = time.time() + 300 print c
5
by: cbhoem | last post by:
Hi - I am trying my hand at python cookies. I'm confused about a few things though. Do the python cookies get written to a cookies text file? I have simple code below -- I see the cookie in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.