|
Posted by Sabine on 10/04/71 11:23
Hello to all,
I think, I have a basic problem of understanding sessions and the
storing of variables in sessions.
I have a simple script I tested on 3 Apache-servers, one with PHP 5.0,
one with 4.3.10 and one with 4.0.6.
I have to develop for the 4.0.6 !!! server.
The output is different for every server.
All servers have session.auto_start off (irrelevant, cause I start the
session myself?) and session.use_cookies on
The PHP4-servers have register_globals on, on the PHP5 it is set to off.
My script is as follows:
session_start();
$test = "";
if (!isset($HTTP_SESSION_VARS['test'])) {
$test = "test";
$HTTP_SESSION_VARS['test'] = $test;
echo "if, test: " . $test . "<br>";
echo "if, sesstest: " . $HTTP_SESSION_VARS['test'] . "<br>";
} else {
$test = $HTTP_SESSION_VARS['test'];
echo "else, test: " . $test . "<br>";
echo "else, sesstest: " . $HTTP_SESSION_VARS['test'] . "<br>";
}
echo "test: " . $test . "<br>";
echo "sesstest: " . $HTTP_SESSION_VARS['test'] . "<br>";
$test2 = "";
if (!session_is_registered('test2')) {
$test2 = "test2";
session_register('test2');
echo "if, test2: " . $test2 . "<br>";
} else {
echo "else, test2: " . $test2 . "<br>";
}
echo "test2: " . $test2 . "<br>";
When I call the script for the first time the output is:
if, test: test
if, sesstest: test
test: test
sesstest: test
if, test2: test2
test2: test2
on all servers.
Additionaly I get a warning for the session_register-part on the
PHP5-server. Thats ok.
But when refreshing the script, I get different output:
PHP5:
else, test: test
else, sesstest: test
test: test
sesstest: test
else, test2:
test2:
That's, what I would have expected.
PHP4.3.10:
else, test:
else, sesstest:
test:
sesstest:
else, test2:
test2:
I don't understand, why the variables seem to be empty.
PHP4.0.6:
if, test: test
if, sesstest: test
test: test
sesstest: test
else, test2:
test2:
I don't understand, why it won't go to the else in the
HTTP_SESSION_VARS-part.
In the session_is_registered-part, the var seems to be empty, too. Why?
I don't want to make use of the register_globals on, so think I should
prefer the HTTP_SESSION_VARS-part.
But what do I get wrong?
It would be very, very nice of you to explain it to me or to give me a
tip where to read more to approach my understanding.
Thank you in advance
Sabine
Navigation:
[Reply to this message]
|