HELP: how much can you store in a cookie/session?

Discussion in 'PHP' started by clinton, Nov 26, 2007.

  1. #1
    I'm working on a site where I am using session variables for the login. I am storing a php object/class in this session. this works fine and I'm storing user variables in the object/class to cut down on database usage. So the user variables are grabbed from the database when the user signs in and stays inside the session until the user logs out or the session expires; so instead of running to the database every time the user needs specific data it just grabs it from the session object. I need to know how much data you can safely store inside a session until something dumb starts happening. If anyone can tell me something important about using this method please do.:)

    thanks

    Clinton
     
    clinton, Nov 26, 2007 IP
  2. jOE :D

    jOE :D Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can almost store more than one cookie or session variable. So you really can store as much stuff as you'd like.
     
    jOE :D, Nov 26, 2007 IP
    clinton likes this.
  3. clinton

    clinton Well-Known Member

    Messages:
    2,166
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Thanks:)

    If I can store as much as I'd like than thats awesome, because the more I store during a session the less I have to grab from the database every time a user changes a page in the user panel.

    thanks for the reply:)
     
    clinton, Nov 26, 2007 IP
  4. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #4
    i think the max is 3-4 kb , saw that some where but not sure ..
     
    commandos, Nov 26, 2007 IP
  5. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #5
    you may be saving on mysql's queries but you are using up your webserver's resources, the webserver maintains these sessions so i dont think its any efficient. just my 2 cents :)
     
    serialCoder, Nov 26, 2007 IP
    clinton likes this.
  6. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #6
    Number and size limits of a cookie in Internet Explorer

    http://support.microsoft.com/kb/306070


    Microsoft Internet Explorer complies with the following RFC 2109 recommended minimum limitations:

    • at least 300 cookies
    • at least 4096 bytes per cookie (as measured by the size of the characters that comprise the cookie non-terminal in the syntax description of the Set-Cookie header)
    • at least 20 cookies per unique host or domain name
     
    commandos, Nov 26, 2007 IP
    clinton likes this.
  7. clinton

    clinton Well-Known Member

    Messages:
    2,166
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    110
    #7
    thanks everyone for the help:)


    I guess I've changed my plans around. I'm only storing info for the most reused data such a user name, id, email, user rating, session expiration, last logged in, date joined/activated and maybe some account options. I guess if I keep my sql queries well optimized I can keep things running fast.

    thanks again
     
    clinton, Nov 26, 2007 IP