Page 1 of 1
Session doesn't work in PHP
Posted: Fri Apr 11, 2003 12:20 pm
by homerwells
I'm beginning to think that session handling just doesn't work in PHP;
This is my script:
<?
function InitializeSession()
{
$HTTP_SESSION_VARS["logged"] = true;
}
InitializeSession();
echo $HTTP_SESSION_VARS["logged"];
echo $_logged;
?>
It prints NOTHING. Does anyone have any idea of what the hell is going on?
Posted: Fri Apr 11, 2003 2:07 pm
by Jim
Try replacing $HTTP_SESSION_VARS with $_SESSION to call sessions.
You might also want to remove the underscore between the $ and logged.
Then again, I'm no pro. Just my two measly bits.

Posted: Fri Apr 11, 2003 2:21 pm
by twigletmac
If you've got PHP 4.1 or above try (as Jim said):
Code: Select all
session_start(); // you must have this at the top of the script
function InitializeSession()
{
$_SESSION['logged'] = true;
}
InitializeSession();
echo $_SESSION['logged'];
If however you're using PHP 4.0.6 or below you might be able to do (this may not work cause it's flaky):
Code: Select all
session_start(); //'cause you can't do sessions without it
function InitializeSession()
{
global $HTTP_SESSION_VARS; // you have to declare this global in order to use it
$HTTP_SESSION_VARS['logged'] = true;
}
InitializeSession();
echo $HTTP_SESSION_VARS['logged'];
otherwise you're going to have to look into using
session_register().
Mac
Posted: Fri Apr 11, 2003 3:45 pm
by Stoker
..and on the first page the var is set you probably nee a
session_register('logged');
as well..
Posted: Sat Apr 12, 2003 4:42 am
by twigletmac
Stoker wrote:..and on the first page the var is set you probably nee a
session_register('logged');
as well..
Although $HTTP_SESSION_VARS and $_SESSION do not play nicely with session_register() - you kinda have to use one or the other, not both. If you can, use $_SESSION.
Mac