Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

PHP Session problem....

Thread Tools
 
Search this Thread
 
Old Feb 7, 2003 | 11:04 AM
  #1  
Dizzy's Avatar
Dizzy
Thread Starter
Scooby Regular
 
Joined: May 2001
Posts: 2,537
Likes: 0
Post

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.
Reply
Old Feb 7, 2003 | 11:49 AM
  #2  
Dizzy's Avatar
Dizzy
Thread Starter
Scooby Regular
 
Joined: May 2001
Posts: 2,537
Likes: 0
Post

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();
}

?>
Reply
Old Feb 7, 2003 | 11:57 AM
  #3  
Andrewza's Avatar
Andrewza
Scooby Regular
 
Joined: Jan 2002
Posts: 667
Likes: 0
Post

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:

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.
Reply
Old Feb 7, 2003 | 12:40 PM
  #4  
Dizzy's Avatar
Dizzy
Thread Starter
Scooby Regular
 
Joined: May 2001
Posts: 2,537
Likes: 0
Post

could be this aswell
"PHP Version 4.0.6"

thanks for the info.. I may roll back and see if I Can get it working the other way
Reply




All times are GMT +1. The time now is 10:27 AM.