PHP Session problem....
#1
I have the following lump of php code included first at the top of my file :
<?
//phpinfo();
session_start();
function session_defaults()
{
$_SESSION['logged'] = false;
$_SESSION['uid'] = 0;
$_SESSION['username'] = '';
$_SESSION['cookie'] = 0;
$_SESSION['remember'] = false;
}
$reset='false';
if (!isset($_SESSION['uid']))
{
$reset='true';
session_defaults();
}
if($_SESSION['uid']==0)
{
if(isset($LoginName))
{
$_SESSION['username']=$LoginName;
$_SESSION['uid']=1;
}
}
?>
However the session stuff doesn't seem to remember from page to page and the $reset flag is always set to true. I've tried setting the session.autostart to 0 and 1 but doesn't make any difference
please help.
<?
//phpinfo();
session_start();
function session_defaults()
{
$_SESSION['logged'] = false;
$_SESSION['uid'] = 0;
$_SESSION['username'] = '';
$_SESSION['cookie'] = 0;
$_SESSION['remember'] = false;
}
$reset='false';
if (!isset($_SESSION['uid']))
{
$reset='true';
session_defaults();
}
if($_SESSION['uid']==0)
{
if(isset($LoginName))
{
$_SESSION['username']=$LoginName;
$_SESSION['uid']=1;
}
}
?>
However the session stuff doesn't seem to remember from page to page and the $reset flag is always set to true. I've tried setting the session.autostart to 0 and 1 but doesn't make any difference
please help.
#2
if anyones interested I've fixed it with this dont trust examples [img]images/smilies/mad.gif[/img].
<?
//phpinfo();
session_start();
function session_defaults()
{
session_register('logged');
session_register('uid');
session_register('username');
session_register('cookie');
session_register('remember');
$GLOBALS['logged']=false;
$GLOBALS['uid']=0;
$GLOBALS['username']='';
$GLOBALS['remember']=0;
$GLOBALS['cookie']='';
$GLOBALS['superuser']=0;
}
$reset='false';
if (!isset($GLOBALS['uid']))
{
$reset='true';
session_defaults();
}
?>
<?
//phpinfo();
session_start();
function session_defaults()
{
session_register('logged');
session_register('uid');
session_register('username');
session_register('cookie');
session_register('remember');
$GLOBALS['logged']=false;
$GLOBALS['uid']=0;
$GLOBALS['username']='';
$GLOBALS['remember']=0;
$GLOBALS['cookie']='';
$GLOBALS['superuser']=0;
}
$reset='false';
if (!isset($GLOBALS['uid']))
{
$reset='true';
session_defaults();
}
?>
#3
I think the $_SESSION["foo"] = 1; is fine, it's just you need to session_register() all variables before you can use them.
You might have been affected by this though:
You might have been affected by this though:
There is a defect in PHP 4.2.3 and earlier. If you register a new session variable by using session_register(), the entry in the global scope and the $_SESSION entry will not reference the same value until the next session_start(). I.e. a modification to the newly registered global variable will not be reflected by the $_SESSION entry. This has been corrected in PHP 4.3.