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

Problem with Cookies

Hi guys

I've come across a problem with cookies. It seems that if one attempts to
save several cookies in quick succession and then read them back again, you
may attempt to read a cookie that has not yet been saved from the first
operation. I assume that this is because JavaScript via the browser hands
the job over to the OS and then merrily proceeds upon its way.

As it happens, I solved the problem by rewriting my code to use one large
cookie that I could split into an array and hold as a global. I could then
manipulate it at will, and only when I had finished with it did I then
reassemble it into a string and then save it as a cookie in one shot.

Just as a matter of interest, I tried saving that same cookie and reading it
back immediately. The result came back as "undefined". But saving it and
then waiting a while (about 15 secs) and then reading it back, I got the
result I'd expected. I cleared the cookies before each test to make sure I
had clean results.

So my questions are this. Am I correct about the lag between JS and the OS?
Is there a methodical way of ensuring that a cookie has been written before
trying to read it back?

I hope I've explained that well enough. Many thanks for any advice.

Ian
Jul 23 '05 #1
2 1372
In article <BD***********************@btclick.com>, ia*********@btclick.com
enlightened us with...
Hi guys

I've come across a problem with cookies. It seems that if one attempts to
save several cookies in quick succession and then read them back again, you
may attempt to read a cookie that has not yet been saved from the first
operation. I assume that this is because JavaScript via the browser hands
the job over to the OS and then merrily proceeds upon its way.

I'm honestly not sure, but don't make that assumption. It could be that.
It could be that javascript is threaded. I never asked that question before,
so I'm not sure if it goes in threads or not. Which would mean that it breaks
off a child process to write the cookie while the main process keeps going.
It could be that the cookie isn't saved at all for a certain amount of time.
I know session cookies aren't saved to disk, so maybe it has to wait for the
OS to give it a place in dynamic memory or something. If it isn't a session
cookie, it may have to wait until a certain amount of data needs saved or
something before it writes to disk.
It could be another reason I'm not thinking of.

Just don't assume.

So my questions are this. Am I correct about the lag between JS and the OS?
I dunno, but don't rule out other things.
Is there a methodical way of ensuring that a cookie has been written before
trying to read it back?


Not that I know of. I've never had this problem. Then again, I don't try to
store a lot of cookies, either. I store one cookie. The rest of the data I
want to associate with a user is stored on the server with the cookie ID as
the key.

--
--
~kaeli~
I love God.
It's His fanclub that I can't stand.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
> Not that I know of. I've never had this problem. Then again, I don't try to
store a lot of cookies, either. I store one cookie. The rest of the data I
want to associate with a user is stored on the server with the cookie ID as
the key.

Yes, the cookie as a key to server data is what's planned and it'll be in
place by the end of next week. I came across this problem as I was
prototyping the pages that are going to be generated by SQL/ASP and I was
doing some crude simulations. I don't use cookies as a rule, either.

The question is purely academic, but many thanks for your input.

By the way, the idea that it might be because JavaScript it threaded is
definitely wrong. JavaScript isn't threaded.

Cheers

Ian

Jul 23 '05 #3

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

Similar topics

2
by: Netanel | last post by:
Hi, I have a site that I developed in ASP / VBScript. Some of the visitors are complaining that they can't get in into the system (using the login form of-course). My login form includes...
7
by: patbaudy | last post by:
Hi, I'm coding a shopping cart in asp. I store all info about ordered items, customer's coordonates, etc...into cookies. When the order is complete I use "CDONTS.NewMail" to send an order...
1
by: rushik | last post by:
Dear all, We have created a business portal for our organization. The technology used for that is LAMP. Our major access management system of the portal is based on cookies. we set some user...
0
by: Claudio | last post by:
I have a demo app where cookies does not work. The first page create a cookies. The second read the contet. If I browse the pages via IE6.0 the pages does not work. If I browse the pages via...
7
by: cmrchs | last post by:
Hi, In Windows Vista: where does asp.net write its cookies? I use HttpCookie objCookie = new HttpCookie("nameCookie"); in Win2000 (and later) they used to be in C:\Documents 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?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.