|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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).
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 26 23:00:01 2025 UTC |
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>"; ?>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.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...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.