Printing the location of the current PHP session file

Posted on 2011-04-20
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.

Question by:level9wizard
    LVL 34

    Expert Comment

    by:Beverley Portlock
    LVL 8

    Expert Comment

    $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 != '..')) {
            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>";

    Open in new window

    LVL 11

    Author Comment


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

    Accepted Solution

    Sorry - it's the ID and it usually gets prefixed with sess_

    My mistake!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to dynamically set the form action using jQuery.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now