Hey all, I'm experiencing unexpected behavior from a session IF.
When I login in, the $_SESSION is set. When I go back to my front page, It doesn't seem to remember me. It has the $_SESSION['user_name'] set to Anonymous. It ran the filter even though the $_SESSION['user_name'] variable was already set, the exact opposite of what I wanted. However:PHP Code:<?php
class SessionFilter
{
public $nextfilter;
public function __construct($nextfilter)
{
$this->nextfilter = $nextfilter;
}
public function execute()
{
if(!isset($_SESSION['user_name'])) // <--- This part
{
session_start();
$_SESSION['user_name'] = 'Anonymous';
$_SESSION['alias'] = 'Anonymous';
$_SESSION['plevel'] = '0';
$_SESSION['loggedin'] = FALSE;
} else {
session_start();
}
$this->nextfilter->execute();
}
}
?>
Does what I want, but exactly the opposite of what I expected. Not only that, but when I go to my front page, the $_SESSION['user_name'] is the same as it was set when I logged in. That means that is isset, rather than !isset.PHP Code:<?php
class SessionFilter
{
public $nextfilter;
public function __construct($nextfilter)
{
$this->nextfilter = $nextfilter;
}
public function execute()
{
if(isset($_SESSION['user_name'])) // <--- Notice isset rather than !isset
{
session_start();
$_SESSION['user_name'] = 'Anonymous';
$_SESSION['alias'] = 'Anonymous';
$_SESSION['plevel'] = '0';
$_SESSION['loggedin'] = FALSE;
} else {
session_start();
}
$this->nextfilter->execute();
}
}
?>
Maybe I'm doing this the wrong way? I'm not very experienced with sessions, so there could be somehting I'm missing.
Hope I was able to communicate my problem clearly.





Bookmarks