Home » Php » php – Is there any way to determine the *actual* session save path?

php – Is there any way to determine the *actual* session save path?

Posted by: admin July 12, 2020 Leave a comment

Questions:

I know there are half a dozen ways to get the value of the session.save_path directive (phpinfo(), session_save_path(), etc.), but when the value is an empty string, as it is by default, the actual path can be any of several locations. I’ve read that it’s usually /tmp, except when it’s /var/lib/php5, but on OS X Mountain Lion it’s definitely /private/var/tmp. On Windows, it’s probably C:\Windows\Temp, but who knows.

I could specify the location, but that won’t really help me. I’m trying to diagnose a tricky problem and I would like to know what the current location is on a server that I don’t have full access to. If there’s a right way to do it, I haven’t been able to find it. I’m open to clever hacks.

How to&Answers:

I have not reviewed the PHP source code to confirm this, but it looks like when session.save_path is empty, PHP uses the value of sys_get_temp_dir() (which varies by user).