We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Printing the location of the current PHP session file

level9wizard
level9wizard asked
on
Medium Priority
316 Views
Last Modified: 2012-05-11
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.

Comment
Watch Question

CERTIFIED EXPERT

Commented:
<?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

Author

Commented:
bportlock,

session_name() is just showing the string PHPSESSID?
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.