session.auto_start and session arrays?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #1

    session.auto_start and session arrays?

    Is there any problem with using session.auto_st art in the php.ini instead of declaring session_start() on every page?

    Also, can sessions store arrays, and if so, is this a good idea?
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    As for autostart, better read the following warning from the PHP mmanual:
    Originally posted by PHP manual
    If you do turn on session.auto_st art then you cannot put objects into your sessions since the class definition has to be loaded before starting the session in order to recreate the objects in your session.
    PHP manual session.auto_st art

    If you mean if the $_SESSION array can hold arrays: yes. And it is an easy way of transferring data between pages.
    Storing arrays in 'flat' variables is somewhat more elaborate, because you have to serialize/unserialize them.

    Ronald

    Comment

    • TheServant
      Recognized Expert Top Contributor
      • Feb 2008
      • 1168

      #3
      So with session arrays: I tried it, but I have realised to use it I will need to write something like:
      [PHP]
      $array = array($_SESSION['array_name']);
      $array['variable_a'];
      [/PHP]

      Is it better to have that done on the page I need to unpack that array and leave only arrays as session variables, or just have 100 session variables which are more easily accessible? Is one quicker that the other?

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        You should take into account that serializing/unserializing can take up a lot of memory storage.
        If you want to just pass an array from one form to another via submit, you can serialize it into a hidden form field.
        But I would still prefer to use flat variables in the $_SESSION array, even 100, in a case where I'd have a lot of pages that will address those variables.

        Ronald

        Comment

        • TheServant
          Recognized Expert Top Contributor
          • Feb 2008
          • 1168

          #5
          Sounds good, that's the way I have it set up at the moment. No other opinions?

          Comment

          • TheServant
            Recognized Expert Top Contributor
            • Feb 2008
            • 1168

            #6
            Thanks heaps ronverdonk, this can be closed.

            Comment

            Working...