Problem with session file path

Discussion in 'PHP' started by mottwsc, Dec 24, 2007.

  1. #1
    These two simple scripts are for a test of session variables. I can pass variables in a form, but not using $_SESSION, even though there is a session ID. The errors being shown (below the two scripts) are related to the incorrect path for session files.

    # sessionTest1.php >>>>
    <?php
    ini_set('error_reporting', E_ALL);
    ini_set('display_errors', 1);
    session_start();
    ?>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Testing Sessions page 1</title>
    </head>

    <body>
    <?php
    $PHPSESSID = session_id();
    $_SESSION['session_var'] = 'session testing';
    echo "This is a test of the sessions feature.
    <form action='sessionTest2.php' method='POST'>
    <input type='hidden' name='form_var' value='form testing'>
    <input type='hidden' name='PHPSESSID' value='$PHPSESSID'>
    <input type='submit' value='go to next page'>
    </form>";
    ?>
    </body>
    </html>

    # sessionTest2.php >>>>
    <?php
    ini_set('error_reporting', E_ALL);
    ini_set('display_errors', 1);
    session_start();
    ?>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Testing Sessions page 2</title>
    </head>

    <body>
    <?php
    echo "PHPSESSID = {$_POST['PHPSESSID']}<br>\n";
    echo "session_var = {$_SESSION['session_var']}<br>\n";
    echo "session_var (2) = ".$_SESSION['session_var']."<br>\n";
    echo "form_var = {$_POST['form_var']}<br>\n";
    ?>
    </body>
    </html>

    # ERROR MESSAGES for sessionTest1.php ************
    Warning: session_start() [function.session-start]: open(C:\DOCUME~1\MICHAE~1.DEL\LOCALS~1\Temp\php\session\sess_ns18p52l859pqdo660mhtbg274, O_RDWR) failed: No such file or directory (2) in C:\Inetpub\wwwroot\sessionTest1.php on line 4
    This is a test of the sessions feature.

    [button]

    Warning: Unknown: open(C:\DOCUME~1\MICHAE~1.DEL\LOCALS~1\Temp\php\session\sess_ns18p52l859pqdo660mhtbg274, O_RDWR) failed: No such file or directory (2) in Unknown on line 0

    Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (C:\DOCUME~1\MICHAE~1.DEL\LOCALS~1\Temp\php\session) in Unknown on line 0

    # *************

    I do not know why this path was specified on install. The path does not exist as far as I can tell. I had installed php in c:\php. So, I created a subdirectory c:\php\session - is this where the session directory should go given my installation directory? Then, I changed the INI file (session.save_path="C:\php\session").

    Once that was changed, I tried to rerun the scripts, but I have the same original wrong path showing up in the error messages. Then, I created another script to destroy the session, cookie, etc. (see code below). However, after running this (and the cookie was removed), I reran the original script in a new browser, but I'm still getting the errors associated with the original path.

    # sessionTestDestroy
    <?php
    ini_set('error_reporting', E_ALL);
    ini_set('display_errors', 1);

    // Initialize the session.
    // If you are using session_name("something"), don't forget it now!
    session_start();

    // Unset all of the session variables.
    $_SESSION = array();

    // If it's desired to kill the session, also delete the session cookie.
    // Note: This will destroy the session, and not just the session data!
    if (isset($_COOKIE[session_name()])) {
    echo "cookie removed";
    setcookie(session_name(), '', time()-42000, '/');
    }

    // Finally, destroy the session.
    session_destroy();
    ?>

    Can anyone help here??
     
    mottwsc, Dec 24, 2007 IP
  2. mottwsc

    mottwsc Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    After rebooting the server so that the new INI file path settings took effect, the problem was solved.
     
    mottwsc, Dec 24, 2007 IP