How to write session_start(); once and run everywhere?

Discussion in 'PHP' started by ketting00, Jun 22, 2011.

  1. #1
    Hi,

    I just want to know if I can get around with with this toil. I've to write session_start(); on every page that I want to use the session values.

    I noticed that some software I've downloaded doesn't use session_start() that often.

    Thanks
    Ket
     
    ketting00, Jun 22, 2011 IP
  2. AdsMakeSense

    AdsMakeSense Active Member

    Messages:
    389
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    70
    #2
    You can include session start in a header, db file and include it in every script?
    Not too sure what you're talking about. Do you not want to use session_start anymore?
     
    AdsMakeSense, Jun 22, 2011 IP
  3. Lam3r

    Lam3r Active Member

    Messages:
    235
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #3
    You could not use sessions, or you could require/include a global file that has session_start() in it on every page that you need sessions.
     
    Lam3r, Jun 22, 2011 IP
  4. mindblaster

    mindblaster Peon

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    write it in your header file and include it in every page
     
    mindblaster, Jun 28, 2011 IP
  5. kajol

    kajol Well-Known Member

    Messages:
    523
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #5
    Here are 2 more useful options:
    Set : session.autostart = 1 in your php.ini file

    if you don't have access to php.ini file, always create session variables using

    session_register() function instead of assigning directly to the $_SESSION global variable. The session_register() function will start the the session if it's not already started...
     
    kajol, Jun 29, 2011 IP
  6. amaudy

    amaudy Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    yeah, put in php.ini might be better
     
    amaudy, Jun 29, 2011 IP