$_SESSION, autostart

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff Sandler

    $_SESSION, autostart

    I just started with a service provider who's giving me a server to put
    my scripts. I noticed when I copy scripts that work on my machine to
    this server, all things $_SESSION are null. I read some on php.net and
    found that session_autosta rt has to be set to true in order for me to
    use $_SESSION variables at all. Am I reading that right? Obviously, I
    have no control over this setting on someone else's server so I cannot
    change it. Is this why my $_SESSION values are all null? Is there a
    workaround? I tried putting session_start() ; at the very beginning of
    the first script. No change.

    Thanks in advance,
    Jeff Sandler
  • Adriaan

    #2
    Re: $_SESSION, autostart

    "Jeff Sandler" wrote[color=blue]
    > I read some on php.net and found that session_autosta rt has to
    > be set to true in order for me to use $_SESSION variables at all.
    > Am I reading that right?[/color]

    No, read on. If you still know where you've read that then please anotate
    that very page with whatever you're learning here...
    [color=blue]
    > Obviously, I have no control over this setting on someone
    > else's server so I cannot change it.[/color]

    This is your lucky day ;-) Note that http://php.net/session states
    PHP_INI_ALL for this option, so you can also override in the PHP script
    itself (well, that could hardly be called "auto start" then; use
    session_start() instead) or when using Apache you can enable it in a
    ..htaccess file in your script's directory, or even in your own root
    directory. See http://php.net/ini-set and


    Note that the correct full name is

    session.auto_st art

    so for Apache you'd use

    php_flag session.auto_st art on

    Note that using session.auto_st art is not always a good choice: you cannot
    put any objects in your session... Again, read http://php.net/session or
    read on to use session_start() ...
    [color=blue]
    > I tried putting session_start() ; at the very beginning of
    > the first script. No change.[/color]

    When not using the auto start setting, you need the session_start() in every
    script that is invoked by your visitor (as in: every page, even if it is not
    using any session data, in order to keep the session alive when the visitor
    is not accepting cookies), not just in the first one.

    In general, you'll see if sessions are working if PHP is trying to set a
    cookie. Type

    javascript:aler t(document.cook ie);

    in the Location / URL / Address field of your browser to see if any cookie
    is set. Furthermore, on the very first page that you started the session on,
    you *might* find that all relative URLs have a PHPSESSID GET parameter
    appended to them (depends on your settings).

    Adriaan.


    Comment

    Working...