简体   繁体   中英

What's the proper use of php.ini's session.save_path?

I'm running PHP on Windows/IIS.

My session variables don't seem to be preserved from page-to-page.

This code…

//echos out the session variables in a nice format for inspection
echo "<p><pre>";
print_r($_SESSION);
echo "</pre></p>";

…outputs blank values, like this…

Array  
    (  
        [s_firstvar] =>  
        [s_var2] =>  
        [s_third] =>  
        [s_numberfour] =>  
        [s_youget] =>  
        [s_thepoint] =>  
        [] =>  
    )

I found suggestions on a forum…

I had a similar problem recently (Win2000, IIS), and it turned out that PHP did not have write-access to whatever directory that the session data was stored in. You may want to look into this.

and

have you set session.save_path?

What's the proper use of php.ini's session.save_path? And, is that my problem?

can you post a bit more of your session code? some basics:

  • did you start your session? ( session_start() )
  • did you check whether your save path has proper permissions (not mentioned in OP)
  • session.save_path is really just the directory sessions will be saved into. if you are on a shared service, it may be better to set it to a different directory than the default temporary directory (as your sessions would be intermingled with other app's sessions as well, and could potentially lead to a greater chance of session collision)
  • if you are altering session configurations (like save_path , these must be set previous to calling session_start() .

Oops. I found that I was not using the correct syntax when assigning values:

Does not work:

$_SESSION['$s_firstvar'] = 3;

Does work:

$_SESSION['s_firstvar'] = 3;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM