Sessions or Cookies?

Discussion in 'PHP' started by killaklown, Aug 29, 2006.

  1. #1
    Which is safer for an administrator panel, cookies or sessions?
     
    killaklown, Aug 29, 2006 IP
  2. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #2
    sessions use cookies, so.... they're just about the same!
    I would use an expiring session, and depending on the level of security you need, have it based on IP as well
     
    frankcow, Aug 29, 2006 IP
  3. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #3
    I dont know much about sessions and cookies, how can i base it off the IP?
     
    killaklown, Aug 29, 2006 IP
  4. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #4
    store the ip in a cookie/session variable, and read it on each page load. if it changes, expire the cookie/session
     
    frankcow, Aug 29, 2006 IP
  5. Litewebsite

    Litewebsite Guest

    Messages:
    26
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Litewebsite, Aug 30, 2006 IP
  6. dalziel

    dalziel Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If you want to be secure, don't store any information in session or cookie, just a randomised string that identifies a row in your database that contains the info you want. The load the data out of the database based on the session/cookie key. This way there's no security issues.

    cheers
    Glenn
     
    dalziel, Sep 4, 2006 IP
  7. themole

    themole Peon

    Messages:
    82
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If you're using sessions, I can still hijack a session, get someone else's unique id that you've stored in the session. Then with that id I'll have the credentials tied to it in the database. The problem is sessions are inherently insecure.

    You should regenerate the user's session id immediately before and after logging in and every 5 or 10 minutes. The single most important thing you can do is validate any data you're receiving from a user. If a username/password is only allowed to be alphanumeric you should check for any non-alphanumeric characters and stop the script cold if you find any. If you have a file upload, validate what types of files are being uploaded.

    -the mole

    *edit*
    here's a decent article on XSS and getting session_ids
    http://www.informit.com/articles/article.asp?p=603037&rl=1 (changed this url to the actual article)
     
    themole, Sep 4, 2006 IP