|
Posted by Michael Windsor on 11/03/06 14:01
Pedro Graca wrote:
> Michael Windsor wrote:
>> if I [...] put "$HTTP_SESSION_VARS = $_SESSION" after
>> session_start(), it stops $_SESSION behaving properly [...]
>>
>> Could this be a bug in PHP?
>
> My PHP does not exhibit that behaviour.
> Can it be that you have /something else/ in your code responsible for
> the behaviour you describe?
>
[snip code]
Your code on my web server exhibits the behaviour I would expect, but it
doesn't quite test the problem I'm having. If your code is amended as
follows:
<?php
session_start();
if (rand(0, 1)) {
echo "Using copy of the \$_SESSION array...<br>\n";
$COPY_SESSION = $_SESSION;
if (rand(0, 1)) {
echo "and not copying it back.<br>\n";
} else {
$_SESSION = $COPY_SESSION;
}
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
}
$val = ++$_SESSION['count'];
} else {
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
}
$val = ++$_SESSION['count'];
}
echo "Current value is $val.<br>\n";
?>
counter increments are only shown on pages following a page where a copy
is NOT taken of $_SESSION (i.e. the final else clause is executed),
regardless of whether the copy of $_SESSION is written back to it or
not. Note that all increments in this version of the code are made
directly to the $_SESSION array, never to a copy: the counter *should*
increment on every page load, as far as I can see. It doesn't on my system.
[Back to original message]
|