How to extend the lifetime of $_SESSION?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mikek12004
    New Member
    • Sep 2008
    • 200

    How to extend the lifetime of $_SESSION?

    I use a $_SESSION variable to store the username and wish to last longer that it does (only for this php script) is there a way?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    sure, overwrite the session.gc_maxl ifetime value with ini_set(). see Session Runtime Configuration

    Comment

    • Dheeraj Joshi
      Recognized Expert Top Contributor
      • Jul 2009
      • 1129

      #3
      Dormilich is right

      change this

      session.gc_maxl ifetime in php.ini........ .

      Comment

      • Canabeez
        New Member
        • Jul 2009
        • 126

        #4
        Following question...

        If you're overriding the session.gc_maxl ifetime in one PHP script, and then run another one under the same session, will the the lifetime "get shorter" after you run the second script?

        Comment

        • dlite922
          Recognized Expert Top Contributor
          • Dec 2007
          • 1586

          #5
          Yes, if you want this value to remain for any page with session, you have to have this declared.

          If you want the entire server (php global setting) just change it in your php.ini like dheerajjoshim suggested vs what Dorm suggested.

          Cheers,



          Dan

          Comment

          • mikek12004
            New Member
            • Sep 2008
            • 200

            #6
            in the php script the in_set("session .gc_maxlifetime ",2000) will go below the session_start() right?

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              I usually set php.ini values as early as possible.

              Comment

              • mikek12004
                New Member
                • Sep 2008
                • 200

                #8
                yeah but can you do it before session_star()? (Normaly isn't this going at the very top?)

                Comment

                • Dormilich
                  Recognized Expert Expert
                  • Aug 2008
                  • 8694

                  #9
                  Originally posted by mikek12004
                  (Normaly isn't this going at the very top?)
                  not necessarily, it just has to be called before any use of $_SESSION and any output.

                  personal note: using a class for sessions comes in handy there because the class will invoke session_start() when necessary (tho you still need to watch out for previous output)

                  Comment

                  • mikek12004
                    New Member
                    • Sep 2008
                    • 200

                    #10
                    Got it, I will try first the init_set and then the session start and if I do not have any errors I will leave it this way, thanks

                    Comment

                    Working...