Change that, I've changed the script a little..here it is;
PHP Code:
<?php
class User
{
private $_sessionExpiry;
private $_userConfiguration;
function User( )
{
$this->_userConfiguration = array( );
$this->_userConfiguration[ "isLoggedIn"] = false;
$this->_sessionExpiry = 5;
}
function LoggedIn( )
{
return isset( $this->_userConfiguration[ "isLoggedIn"]) ? $this->_userConfiguration[ "isLoggedIn"] : false;
}
function Login( $username, $password )
{
$result = false;
$database = Database::GetInstance();
$query = "SELECT members.* , roles.*
FROM members
LEFT JOIN roles ON ( roles.id = members.role )
WHERE username = '{$username}'
AND members.password = PASSWORD( '{$password}')";
$checkLogin = $database->Query( $query);
if( $checkLogin && $database->RowCount( ) > 0)
{
$user = $checkLogin[ 0];
$this->_userConfiguration[ "username"] = $user[ 'username'];
$this->_userConfiguration[ "email"] = $user[ "emailaddress"];
$this->_userConfiguration[ "name"] = $user[ 'title'] . " " . $user[ "initials"] . " " . $user[ "surname"];
$this->_userConfiguration[ "isLoggedIn"] = true;
$this->_userConfiguration[ "role"] = $user[ 'role'];
$this->_userConfiguration[ "allowInsert"] = $user[ "allowInsert"];
$this->_userConfiguration[ "allowDelete"] = $user[ "allowDelete"];
$this->_userConfiguration[ "allowView"] = $user[ "allowView"];
$this->WriteCookie();
$result = true;
}
return $result;
}
function Logout( )
{
setcookie( "currentInfo",
addslashes(serialize(array())),
(time( ) - 31500000),
"/");
}
function Create( )
{
if( !$this->ReadCookie( ))
{
$sessionId = "";
while( strlen( $sessionId) < 32)
$sessionId .= mt_rand( 0, mt_getrandmax( ));
$this->AddData( "sessionId", md5(uniqid( $sessionId)));
}
}
function WriteCookie( )
{
$sessionData = serialize( $this->_userConfiguration);
if(!setcookie( "currentInfo",
$sessionData,
time() + 60 * 60 * 24 * $this->_sessionExpiry,
"/"))
{
echo " Failed to set cookie ";
exit( );
}
}
function ReadCookie( )
{
if( isset( $_COOKIE[ "currentInfo"])){
$this->_userConfiguration = array( );
$this->_userConfiguration = unserialize( $_COOKIE[ "currentInfo"]);
return true;
}
return false;
}
function AddData( $key, $value)
{
if( !array_key_exists( $key, $this->_userConfiguration))
$this->_userConfiguration[ $key] = $value;
$this->WriteCookie( );
}
function GetValue( $key)
{
if( is_array( $this->_userConfiguration))
{
if( array_key_exists( $key, $this->_userConfiguration))
return $this->_userConfiguration[ $key];
} else
echo " INVALID ARRAY ";
return null;
}
function CheckPermissions( $request )
{
$result = false;
$database = Database::GetInstance( );
if( substr( $request, strlen( $request) - 1, 1) == "/")
$request = substr( $request, 0, strlen( $request) - 1);
if( isset( $this->_userConfiguration[ "role"]))
{
$query = "SELECT * FROM permissions WHERE feature = '{$request}'";
$permissions = $database->Query( $query);
if( $permissions && $database->RowCount( ) > 0)
{
$permission = $permissions[ 0];
if( $permission[ 'permissions'] & $this->_userConfiguration[ "role"])
$result = true;
}
}
return $result;
}
}
This is the user login. It appears to be setting the cookie now (using developer toolbar to examine contents of cookie) , but it's not reading it back loading the array $this->_userConfiguration