cancel
Showing results for 
Search instead for 
Did you mean: 

get absolute path value in PHP for session.save_path

jah
Grafter
Posts: 43
Thanks: 2
Registered: ‎09-06-2007

get absolute path value in PHP for session.save_path

Hi folks,
I'm setting [tt]ini_set( "session.save_path", PATH)[/tt] to a directory under my ccgi space (rather than use [tt]/tmp[/tt]) and through a bit of trial and error I found that the PATH value needs to be the absolute path to the directory :
/share/storage/nn/us/username/sess (where nn is a number, us is the fist two letters of my username and sess is the folder in which my session data will go).
Now this is fine and all, but what I'd like is to programmatically retrieve this value for PATH so that should it change, my php sessions will continue to work.  After much head scratching, I finally got the answer I was looking for and thought I'd share it.
[tt]echo( __FILE__ );[/tt] gives me the full resolved path to the current php file: /share/storage/nn/us/username/some_folder/some_file.php
[tt]echo( $_SERVER['SCRIPT_NAME'] );[/tt] gives me the path of the current php file relative to the document root "/": /some_folder/some_file.php
So the following snippet of code works out the absolute path to the document root, appends my session folder name "sess" and then sets this as the PHP session.save_path:

$session_folder = substr( __FILE__, 0, strlen( __FILE__ ) - strlen( $_SERVER['SCRIPT_NAME'] ) + 1 )."sess";
ini_set( "session.save_path", $session_folder);

/share/storage/nn/us/username/sess
Hurrah!  Maybe useful to someone in the future (and my memory being what it is, possibly me too), but if anyone has any other bright ideas, speak-up!
3 REPLIES 3
spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: get absolute path value in PHP for session.save_path

I'm not familiar with CCGI but on PAYH $_SERVER['DOCUMENT_ROOT'] gives this parameter's absolute path. Does that PHP variable also exist with the older version of PHP on CCGI?
David
jah
Grafter
Posts: 43
Thanks: 2
Registered: ‎09-06-2007

Re: get absolute path value in PHP for session.save_path

I did try [tt]$_SERVER['DOCUMENT_ROOT'][/tt] which does exist on ccgi, but it didn't work for me.  I think this is a symlink (for me the value is /files/home1/username/) whereas the save_path seems to require a resolved path.
spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: get absolute path value in PHP for session.save_path

Thanks, it's useful to know the values differ on CCGI.
David