Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Location
    UK, derby
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Restricted number of Cookies in IE7

    Hi

    Has anyone come across a restricted number of cookies in IE7.

    I have several pages that ll write cookies, then on the final page all the cookies are displayed, it works in FF but not IE7.

    With IE7 if I write 20 cookies then access them they are all present and correct. If I then write a another cookie, then one of the previous 20 cookies is lost and overwritten. If I print out all cookies for localhost there are only ever 20, never any more no matter how many I try and create.

    Whats going on?

    Thanks

    Jake

  • #2
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It looks like you are correctliy. Google found this for me

    http://paul.annesley.cc/articles/200...-cookie-limits

    david_kw

  • #3
    Regular Coder
    Join Date
    Feb 2004
    Location
    UK, derby
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for that, guess I'll have to re-think my elements of my site. Damn IE7!

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,641
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Browsers are only supposed to keep the last 20 cookies set by a given site so IE7 is behaving correctly in that regard. Having other browsers not complying with the standards by keeping more cookies from a site than they are supposed to can lead to other problems especially if they comply with the maximum nunber of cookies overall that they are supposed to keep.

    The only browser I know of that doesn't follow the cookie rules properly is IE6 which only allows a site to store 4k of data in total across the 20 cookies instead of allowing them to store 4k each.

    Once you try to store a 21st cookie for a site or the 300th cookie overall the least recently referenced cookie will be deleted and replaced by the new one being set. It is possible that the cookie that is cleaned up when the 300 cookie limit is reached could be from the same site as the new one you are setting if it was set some time ago so you can only rely onn being able to reach 20 cookies if you set them all during the same visit.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Based on what felgall is saying, it sounds like it would be better to have only one cookie per domain and manage it yourself. So instead of having cookies with values like

    cookie 1 - "pizza"
    cookie 2 - "large"
    cookie 3 - "extra pepperoni"

    You'd have

    cookie 1 - "c1=pizza&c2=large&c3=extra pepperoni"
    cookie 2 - undeclared
    cookie 3 - undeclared

    Something like that. That way you keep the total number of cookies down and if you lose one value you lose them all so you are less likely to get some odd effects where only half the cookies are still there.

    david_kw

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,641
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Since IE6 limits you to 4096 bytes of data per site rather than per cookie the use of multiple cookies on the same site is not as useful as it could be.

    Simplest use of a cookie is to just store a unique id in the cookie and store everything else in a database on the server. Then you read the cookie and lookup the database to find as much info as you needed to store all nicely arranged into separate fields. It keeps the information to be stored in the cookie to a minimum and avoids any privacy concerns relating to the content of the cookie.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    Regular Coder
    Join Date
    Feb 2004
    Location
    UK, derby
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the info, I have done what David_KW mentioned and stored more than one piece of info in a cookie, this has taken the total number below 20.

    Thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •