session_start never initiated, still session starts with $_SESSION[]

Discussion in 'PHP' started by nekowai, Nov 22, 2012.

  1. #1
    php.ini session.auto_start = 0
    I never initiated session_start(), print_r($_SESSION) return null but as soon I make $_SESSION['var'] = 'content'; the session array magically shows in print_r

    Is this normal? :confused:
     
    nekowai, Nov 22, 2012 IP
  2. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #2
    of course it is.

    The same as setting $var['x'] = 'y'; print_r($var); => shows array info
     
    gapz101, Nov 22, 2012 IP
  3. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #3
    I agree, its just a localy set variable, but will not be taken to a next page... as when you start with session_start(); these variables will be saved and available on the next page.
     
    EricBruggema, Nov 23, 2012 IP
  4. nekowai

    nekowai Well-Known Member

    Messages:
    256
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    130
    #4
    Ah, I know what happened, the data probably is coming from the cookie I have set.
    It reads the cookie and fills the $_SESSION array once in the condition it's empty, but since the SESSION never saves, the cookie keeps filling it on every page :confused:
     
    nekowai, Nov 23, 2012 IP
  5. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #5
    The array exists, but it's null (never written to) until you write to it. That's normal for a superglobal.
     
    Rukbat, Nov 23, 2012 IP