When to use session and when to use cookie

Discussion in 'PHP' started by eniyan_admin, Oct 14, 2009.

  1. #1
    Hi all,

    Could anybody tell me exactly when to use session and when to use cookie with example.

    Thank you all.
     
    eniyan_admin, Oct 14, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Sessions are to be used for data that the user should not be able to tamper with. It's more secure. Things like access level, user id and so on.
     
    premiumscripts, Oct 14, 2009 IP
  3. pneulameiro

    pneulameiro Peon

    Messages:
    440
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Very good explanation premiumscripts. I would add just that sessions are for many data, of many types, cookies just for few data, and not of complex types. also remember that cookies are in the client computer. if you make them big the site load time will be great too.
     
    pneulameiro, Oct 15, 2009 IP
  4. LOD

    LOD Member

    Messages:
    319
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    35
    #4
    if u want security use session.. otherwise u can go with cookie...
     
    LOD, Oct 23, 2009 IP
  5. Om ji Kesharwani

    Om ji Kesharwani Peon

    Messages:
    211
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You can use session for storing Id or secured elements.
    And in case of no security issue like storing the products, n all in shopping sites you can go through cookie.
     
    Om ji Kesharwani, Oct 23, 2009 IP