From:             johns582 at mail dot msu dot edu
Operating system: Debian 4.1.1; FreeBSD 4.8
PHP version:      5.2.4
PHP Bug Type:     Session related
Bug description:  $_SESSION data not written if var populated from function 
first

Description:
------------
We use a function (see below) to populate variables based on whether there
is a key present in the $_GET, $_POST, or $_SESSION arrays. After this
function is called and the result assigned to a variable, we save the
variable in a session with:

$_SESSION['var'] = $var; 

The result of this statement is that the variable $var is successful
stored in $_SESSION but is not saved to the session file, which is what we
expect. We can correct the problem by taking the logic in the function
below out of the function and placing it into the body of the main script.
We've also noticed that even when the function is called by the main
script, but not used to assign a value to a variable we intend to store in
a session, this is enough to "break" the session in the manner described
above (e.g.,

//DOESN'T WORK TO MAKE $f_name and $l_name appear in the session file
//even though we aren't actually storing the value of $f_name_p or
//$l_name_p in the session. But works if lines 3 and 4 are removed.
$f_name = $_POST['f_name']; 
$l_name = $_POST['l_name']; 
$f_name_p = populate_rev ("f_name", $_GET, $_POST, $_SESSION);
$l_name_p = populate_rev ("l_name", $_GET, $_POST, $_SESSION);
$_SESSION['f_name'] = $f_name; 
$_SESSION['l_name'] = $l_name; 

One last point: This problem occurs with both the default "files" session
handler and a custom db-backed handler. Using the db-backed handler, we can
confirm that the overloaded "write" function received a session key, but no
data.

Reproduce code:
---------------
function populate_rev ($array_index, $_GET, $_POST, $_SESSION) { 
        
        if (isset($_GET["$array_index"])) { 
                $var = $_GET["$array_index"]; 
        }       
        elseif (isset($_POST["$array_index"])) { 
                $var = $_POST["$array_index"]; 
        } 
        elseif (isset($_SESSION["$array_index"])) { 
                $var = $_SESSION["$array_index"]; 
        } 
        else { 
                $var = ''; 
        }       
        return $var; 
}

Expected result:
----------------
Expected to see the string f_name|s:7:"Heather";l_name|s:7:"Johnson";
present in the session file or in the database (depending on which handler
was currently being used), for example, following assignment of $f_name and
$l_name to the corresponding key in $_SESSION and termination of the
script.

Actual result:
--------------
Even though the $_SESSION array contains the expected key/value pairs, the
session file or database row (in the case of our custom handler) doesn't
contain them. No data is passed to the session write function in the case
of the custom handler. Moving the function's logic into the main body of
the script, or abandoning the function in favor of straight assignment from
the $_POST vars array is the only way to produce the expected result.
(e.g.,

$f_name = $_POST['f_name'];
$l_name = $_POST['l_name'];

-- 
Edit bug report at http://bugs.php.net/?id=42774&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42774&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42774&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42774&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42774&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42774&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42774&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42774&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42774&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42774&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42774&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42774&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42774&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42774&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42774&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42774&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42774&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42774&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42774&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42774&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42774&r=mysqlcfg

Reply via email to