Printing the location of the current PHP session file

Is it possible to print the location of the current session file? I know I can do ini_get( 'session.save_path') to see the path (in my case it's /tmp) - but i'm more interested if it's possible to see the actual file name.

LVL 11
level9wizardAsked:
Who is Participating?
 
Beverley PortlockCommented:
Sorry - it's the ID http://www.php.net/session_id and it usually gets prefixed with sess_

My mistake!
0
 
Beverley PortlockCommented:
0
 
kivan24Commented:
<?php
$Session_Directory = session_save_path().'/';
$Session_File_Name_Prefix = 'sess_';

// current session file is
print $Session_Directory . $Session_File_Name_Prefix . session_id();

// all session files
$DirectoryHandle = @opendir($Session_Directory);
while(($FileHandle = @readdir($DirectoryHandle))!==false) {
    if (($FileHandle != '.')and($FileHandle != '..')) {
        $full_path=$Session_Directory.$FileHandle;
        clearstatcache();
        if ((!(@is_dir($full_path)))&&
            (strpos($FileHandle, $Session_File_Name_Prefix)!==false)&&
            (strlen($FileHandle)==37)) {
            $filecontent=file_get_contents($full_path);//read file content
            print $FileHandle.'<br>'.$filecontent."<hr>";
        }
    }
}
if($DirectoryHandle){
    closedir($DirectoryHandle);
}
?>

Open in new window

0
 
level9wizardAuthor Commented:
bportlock,

session_name() is just showing the string PHPSESSID?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.