Session ID for shopping cart

Discussion in 'PHP' started by Kyriakos, May 19, 2008.

  1. #1
    Hi,

    i want to create a shopping cart but i don't know how to set automatically a sessionID for each user that uses the cart. i want my cookie to expires after 1 hour or when the user closes his browser window. can anyone help me?

    thanks in advance.
     
    Kyriakos, May 19, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Start here:
    http://php.net/session

    To set a session:
    session_start();

    This must be before any output. Best to set the session as the very first thing on a page.

    To get the session id:
    $session_id = session_id();

    You will need to set session.gc_maxlifetime, session.cookie_lifetime in php.ini or .htaccess or at the top of each script to get the sessions to expire in 1 hour.
     
    jestep, May 19, 2008 IP