on most servers i have noticed that it works fine to just use
session_start();

but a few servers require a session_save_path

i'm writing an installer that i would like to auto-configure on servers which require a session save path,

any suggestions how to do this would be great,

    How is PHP supposed to know if a certain host requires the user to specify their own session save path?

    The only way I could see you determining this is if any of the following are true:

    1. The session.save_path directive is empty

    2. The session.save_path directive points to an invalid directory

    3. The session.save_path directive points to an unwritable directory

      So, check [man]is_writable/man on session.save_path, and if it fails, loop through an array of likely names. /tmp, /var/tmp, c:\windows\temp, and %userprofile%\appdata\local\temp might be enough....

        dalecosp;10967501 wrote:

        if it fails, loop through an array of likely names. /tmp, /var/tmp, c:\windows\temp, and %userprofile%\appdata\local\temp might be enough....

        Eh... I disagree. For one, there's no need to blindly "guess" at the correct path - there are environment variables available to tell you where to find the system's default temporary directory.

        However, PHP will automatically set session.save_path to point to this temp directory on its own, so if the server operators have specifically altered that, then it must be for a reason (e.g. the user is supposed to store the files in his/her own home directory (above the web root, of course)). In other words, if the session.save_path isn't valid, then the best solution would be to prompt the user for a new location to save the session files.

          bradgrafelman;10967506 wrote:

          Eh... I disagree. For one, there's no need to blindly "guess" at the correct path - there are environment variables available to tell you where to find the system's default temporary directory.

          I had a bit of difficulty recalling just what I needed in PHP to do this. On all my boxen, phpinfo() reports a valid path already, and no other references to a temp dir, iirc. Python:

          import os;
          print os.environ['TMP'];

          Can't believe I'm resorting to Python instead of PHP though. Something's wrong with me these days....

            Yes; strangely enough:

            c:\windows\users\kadmin>php -r "print_r[$_ENV];" 
            Array
            (
            )

            And:

            [17] Thu 04.Nov.2010 11:21:46
            [kadmin@archangel][~/scripts] cat env.php
            <?php
            
            print_r($_ENV);
            echo "My username is ". $_ENV["user"] . " .";
            
            ?>
            [18] Thu 04.Nov.2010 11:21:47
            [kadmin@archangel][~/scripts] php env.php
            Array
            (
            )
            PHP Notice:  Undefined index: user in /usr/home/kadmin/scripts/env.php on line 5
            My username is  .  

            Is $_ENV only available from the SAPI module?

              Write a Reply...