Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Printing the location of the current PHP session file

Posted on 2011-04-20
4
Medium Priority
?
291 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.

0
Comment
Question by:level9wizard
  • 2
4 Comments
 
LVL 8

Expert Comment

by:kivan24
ID: 35433892
<?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
 
LVL 11

Author Comment

by:level9wizard
ID: 35433902
bportlock,

session_name() is just showing the string PHPSESSID?
0
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 2000 total points
ID: 35433921
Sorry - it's the ID http://www.php.net/session_id and it usually gets prefixed with sess_

My mistake!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question