php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33585 Session saved file empty.
Submitted: 2005-07-06 11:58 UTC Modified: 2005-07-06 14:40 UTC
From: piero dot mac at gmail dot com Assigned:
Status: Not a bug Package: Session related
PHP Version: 5.0.4 OS: WIN XP HOME sp2
Private report: No CVE-ID: None
 [2005-07-06 11:58 UTC] piero dot mac at gmail dot com
Description:
------------
When using $_SESSION in order to transfer POST form informations to others or to the same page with refresh, and data transfert from $_POST to $_SESSION has done as the follow:

$_SESSION = $_POST;

No data session will be stored into session save data file.
Session file is empty.
This problem didn't exist to previous php releases.

Reproduce code:
---------------
<?php
session_start();
// any POST data incoming from FORM is true

if(isset($_POST)) {
$_SESSION = $_POST;
} else { 
$_POST = $_SESSION; }

print_r($_POST);
print_r($_SESSION);
?>

Please, try to page refresh now


Expected result:
----------------
I'm waiting for the same value printed as the first time to any following refresh.



Actual result:
--------------
Problem is possible to bypass with previus creation of empty $_SESSION 
$_SESSION = array(); 

or to transfer to $_SESSION all values one by one (using foreach).

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-06 12:21 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.

Can't reproduce.
Please set display_errors to On and error_reporting to E_ALL in your php.ini and see if there are any error messages.
 [2005-07-06 13:08 UTC] piero dot mac at gmail dot com
No errors or notices are displayed.
Im sorry, but right now, I don't have any available URL at this time.

Here you find all reproduced bug code:
pag1.php
<?php
$html = <<<EOD
<html><body><form action = "page2.php" method = "post">
name <input type="text" name="nick" value="pippo"><br />
city <input type="text" name="city" value ="Turin"><br />
<input type="submit" name="submit" value = "submit">
</form></body></html>
EOD;
echo $html;
?>

page2.php
<?php
session_start();
if(isset($_POST)) {
$_SESSION = $_POST; }
else {
$_POST = $_SESSION; }
echo "<pre>";
print_r($_POST);
print_r($_SESSION);
echo "<a href='bug2.php'>refresh</a>";
?>
 [2005-07-06 13:16 UTC] tony2001@php.net
$_POST is always set, it's just empty when there is no POST data.
So it comes that you set _SESSION to empty array().
No bug here -> bogus.
 [2005-07-06 13:19 UTC] piero dot mac at gmail dot com
Sorry, but I see a refresh link error in page2.php 

Last line is href = "page2.php" and not href=bug2.php....

page2.php <-- correct version, thanx. 

<?php
session_start();
if(isset($_POST)) {
$_SESSION = $_POST; }
else {
$_POST = $_SESSION; }
echo "<pre>";
print_r($_POST);
print_r($_SESSION);
echo "<a href='page2.php'>refresh</a></pre>";
?>

After page refresh $_SESSION is empty and any session data stored in session save file.
 [2005-07-06 13:26 UTC] piero dot mac at gmail dot com
ref.
$_POST is always set, it's just empty when there is no POST data.
So it comes that you set _SESSION to empty array().
No bug here -> bogus.

Problem is not POST of course is empty after refresh page. Problem is "NO DATA had stored in session save file".

you can try also:

if(isset($_POST) && !empty ($_POST)) {

Php 5.0.3 and previoulsy are true.

Thanx any way...
 [2005-07-06 13:28 UTC] tony2001@php.net
Read carefully my last comment.
Change isset() to !empty() and see that it works perfectly.

 [2005-07-06 14:40 UTC] piero dot mac at gmail dot com
Ok. Maybe it's my fault don't explain very well the problem. I try again ... the last. Forget $_POST. Find here another example:
Page1.php
<?php
session_start();
$_test = array('one'=> 'first','two' => 'second', 'last'=>'last');
$_SESSION = $_test;
echo "<pre>";
print_r($_test);
print_r($_SESSION);
echo "<a href='page2.php'>to page 2</a>";
?>

page2.php
<?php
session_start();
     echo "<pre>";
     print_r($_SESSION);
?>

$_SESSION in page2.php is empty. It's no good.

try now another one.

Page1_a.php
<?php
session_start();
$_test = array('one_a'=> 'first','two_a' => 'second', 'last_a'=>'last');

  foreach($_test as $key => $value)  {
    $_SESSION[$key] = $value;
    }
echo "<pre>";
print_r($_test);
print_r($_SESSION);
echo "<a href='page2.php'>to page 2</a>";
?>

now $_SESSION is correctly full.

I repeate once again... before rel. 5.0.4 never happen this
problem.

Nothing to do with POST, isset() or empty(). Only it was the more lighting problem for me.

Thnx for the attention and best regard.
 [2010-06-17 09:54 UTC] thomas dot garbler at yahoo dot com
I admit, the problem is here. PHP v5.1.2 (Apache v2.2.0 with "mass virtual hosting")

empty session file. I'm trying to install UebiMiau v2.7.11 webmail system. It took me two days to understand what's going on. $_SESSION gets modified correctly even using references but never get written to session file.

also the sample provided by "piero dot mac at gmail dot com" works as stated, i.e. $_SESSION isn't working as expected.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 10 12:01:33 2025 UTC