Page 1 of 1

session handling

Posted: Thu Jul 18, 2002 4:53 am
by jai_lamba
hi
I am trying to execute this code but this is not functioning. This always return 0. I dont want to use session_register().


<?php
if (isset($HTTP_SESSION_VARS['count'])) {
$HTTP_SESSION_VARS['count']++;
}
else {
$HTTP_SESSION_VARS['count'] = 0;
}
?>
Thanks
Jai

Posted: Thu Jul 18, 2002 5:09 am
by twigletmac
You really should have added this to the bottom of your previous post - there is no need to start a new topic.

In order to use sessions you must have session_start() at the top of any scripts that set session variables or try to use them.

Mac

but now it's me who is having a question...

Posted: Thu Jul 18, 2002 7:31 am
by Buggy007
I'm registering on my first page session variables:

$_SESSION["strTest"] = "hello";

This works, but when I try to access the variables on the next page, it doesn't, though I have put

session_start();

on top of the code. I can register new variables, but

$_SESSION["strTest"]

is not known.
What can be wrong? Is there something missing? I checked several examples, but it seems to be the same - only one difference: the others work... :(

Posted: Thu Jul 18, 2002 7:36 am
by twigletmac
What version of PHP are you using? $_SESSION won't work as expected (it'll just be a normal array) in versions less than 4.1. For older versions you would use $HTTP_SERVER_VARS instead.

Mac

4.1.2

Posted: Thu Jul 18, 2002 7:42 am
by Buggy007
hi,
I#m working with PHP 4.1.2 .. so this shouldn't be the problem... The registration works, but there's nothing left on the next page. I've got that feeling that there's something missing on this next page, but can't say what, session_start(); ist placed right on top...

(By the way, I tested with $HTTP_SERVER_VARS, it doesnt work, too.)

ok...

Posted: Thu Jul 18, 2002 8:46 am
by Buggy007
if you use $_SESSION with PHP 4.1.2, you HAVE to register it by session_register("_SESSION");