Currently i've got a working database class for MySql interaction, the function that i use is:
Code:
function newdb()
{
//host, username variables etc are defined here but i removed for security
$db = new db();
$connection = $db->connect($dbhost, $dbusername, $dbpassword, $db_name);
return $db;
}
That works fine, i often use it to call things like $db->query($sql); and whatnot.
What i'm currently trying to do is check whether a user is logged in, what authorisation level they are and then return a user class that i can then do things with (classes: guest, user extends guest, mod extends user, admin extends user - you get the idea)
The function i'm trying to use to create a new $user dependent on the rank that's stored in the database is:
Code:
function createuser()
{
// if the user is logged in, create the user based on rank and set all the details (from the database) as class properties
if(isset($_SESSION['logged_in']))
{
if($_SESSION['userrank'] == 1)
{
$user = new user($_SESSION['userid']);
$user->setuserdetails();
}
elseif($_SESSION['userrank'] == 2)
{
$user = new moderator($_SESSION['userid']);
$user->setuserdetails();
}
elseif($_SESSION['userrank'] == 3)
{
$user = new administrator($_SESSION['userid']);
$user->setuserdetails();
}
}
else
{
$user = new guest();
}
return $user;
}
The session variables are fine (i've checked them) and are set upon login. I've done a little debugging and i've found that without logging in, it appears to set the $user variable but it doesn't seem to like returning it properly.
Running this:
Code:
else
{
$user = new guest();
$user->testecho();
}
Also works as it should (i.e. just before the function returns $user) and echoes out a test message to the browser.
Simply creating a user in the main page works, and i can call methods fine, it's just when i try to get it from the function it plays up. Am i missing something obvious?