Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
get absolute path value in PHP for session.save_path
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- get absolute path value in PHP for session.save_pa...
get absolute path value in PHP for session.save_path
08-02-2009 12:39 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
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:
/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!
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!
Message 1 of 4
(3,062 Views)
3 REPLIES 3
Re: get absolute path value in PHP for session.save_path
08-02-2009 1:23 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
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
Message 2 of 4
(579 Views)
Re: get absolute path value in PHP for session.save_path
09-02-2009 7:14 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
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.
Message 3 of 4
(579 Views)
Re: get absolute path value in PHP for session.save_path
09-02-2009 10:49 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Thanks, it's useful to know the values differ on CCGI.
David
Message 4 of 4
(579 Views)
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- get absolute path value in PHP for session.save_pa...