php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32886 Session dont store the correct values
Submitted: 2005-04-29 08:45 UTC Modified: 2005-04-29 12:42 UTC
From: luis at infomed dot sld dot cu Assigned:
Status: Closed Package: Session related
PHP Version: 5.0.4 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: luis at infomed dot sld dot cu
New email:
PHP Version: OS:

 

 [2005-04-29 08:45 UTC] luis at infomed dot sld dot cu
Description:
------------
php5.0.4 dont store the correct values after modified the $_SESSION variable, the idea is to clear the session and do persist only a few values. I use Apache 1.3.33. With php5.0.2 everything is fine the problem appear with php5.0.4, I am not try with php5.0.3


Reproduce code:
---------------
page1.php-----------------------------------------

<?php
session_start();
$_SESSION['varA'] = 'aaa';
$_SESSION['varB'] = 'bbb';
?>

page2.php-----------------------------------------

<?php
session_start();
$buffer['varA'] = $_SESSION['varA'];
$_SESSION = array();
$_SESSION = $buffer;
print_r($_SESSION);
?>

page2b.php-----------------------------------------

<?php
session_start();
$_SESSION = array();
$_SESSION['varA'] = 'aaa';
print_r($_SESSION);
?>

page3.php-----------------------------------------

<?php
session_start();
print_r($_SESSION);
?>


Expected result:
----------------
I would expect the same behavior with:
page1.php->page2.php->page3.php
and with:
page1.php->page2b.php->page3.php
but is not.


Actual result:
--------------
When I do page1.php->page2.php on the screen I obtain the correct values:
Array ( [varA] => aaa )
but on the session file in disc is wrong, because the session file have:
varA|s:3:"aaa";varB|s:3:"bbb";
and in page3.php on the screen I have:
Array ( [varA] => aaa [varB] => bbb ), is wrong.

But, if I do page1.php->page2b.php->page3.php everything is fine.

Thank you for your work in PHP.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-29 09:08 UTC] derick@php.net
Not a bug. If you overwrite the $_SESSION array by assigning a new array to it, you remove it's magic properties of being the array with session variables. This is expected - so don't do it.
 [2005-04-29 11:15 UTC] luis at infomed dot sld dot cu
Please, maybe, I dont explain the problem very well, I try to overwrite the session array but dont work, look at the page2:
$buffer['varA'] = $_SESSION['varA'];
$_SESSION = array();//here I clear the session,become empty
$_SESSION = $buffer;//assign a new array,cause array $buffer
print_r($_SESSION);
//on screen the right result,
//but on the session file is wrong.

So, I want to overwrite the session variable with a new array but php dont do it, then, the onscreen result between page2 and page3 are different and it is not correct because in both pages I have the same statement: print_r($_SESSION); with different results.
Please, if you can, read carefully my tests.
Best regards,
Luis
 [2005-04-29 11:19 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 [2005-04-29 12:42 UTC] luis at infomed dot sld dot cu
OK, I don't know but if you do a cast to $buffer everything fine, so, the new code is:
$buffer['varA'] = $_SESSION['varA'];
$_SESSION = array();
$_SESSION = (array) $buffer; //*** NOTE the cast ***
print_r($_SESSION);

Thanks
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 00:01:30 2024 UTC