View Full Version : Do you put your faith in cookies?

04-03-2003, 03:51 AM
I have always EXPECTED cookie data to be good. For example, I will write "lb" or "kg" to a cookie to keep track of how my visitors weigh themselves. Then when they come back, I check for a cookie. If it's null, I default to "lb." But if it's not null, I use the data trusting that it will be good.

I could check to see that it's "lb" or "kg" and then use it and default to "lb" if it's neither, but I've never bothered. I'm wondering if I should?

I spent the better part of the day trying to find a problem which it turned out was caused by a browser. (The previous version of the WebTV simulator didn't store cookies at all; it seems that this one only stores part of them. Unless I'm somehow causing it but my code works fine with IE and N 4 & 7.)

I was saving a cookie containing 18 data fields using "=" as a control code to separate them. Then EXPECTING to find all the data in the cookie I wrote I had a routine that read all 18 fields. Problem was, today there were only about 6. My website hung.

I solved the problem with a simple routine to check for the 18 control codes. If I don't find all 18, I just don't use the cookie and use defaults as if it were null.

I suppose I should start thinking about this possibility more often. I am not willing to code my site for a user without cookies enabled, but I don't want an occasional failure to cause my site to crash.

04-03-2003, 04:27 AM
cookies are good for stuff that isn't incredibly important.

04-03-2003, 12:09 PM
I've never had any problems storing name=value& pairs in cookies (providing you escape the data before writing to the cookie); but all the same - it's much easier just to keep a session or user ID in the cookie, and store the user's data server-side.

04-03-2003, 04:24 PM
Assuming you have a clue how to do anything on the server side.

04-03-2003, 05:17 PM
Storing data in client-side cookies is about only good for storing user preferences when you do not require them to login to your site. You obviously wouldn't want to store anything important or ciritical in them as chrismicelli suggested since users can disable cookies.