I have this code currently inside of my page.
<?php
if ($admin->get_permissions()==3)
echo 'Welcome Administrator';
elseif ($admin->get_permissions()==1)
echo 'Welcome User';
else
echo 'Welcome Guest';
?>
Now if you’re logged in as an admin or a standard user it works fine, but if you’re visiting the site as a guest then it gives the error
Call to a member function get_permissions() on a non-object in
The error begins at the start of this script. How could I make sure that the get_permissions function works for people logged in and displays custom data for them and also displays information for a guest logged in?
I’ve been racking my brain around this to no avail. If anybody can help it’d be much appreciated.
It seems your
$adminobject isn’t created if the user isn’t authenticated. To fix this you need to either instantiate the object independently on user authentication or introduce a different check for permissions, maybe something like this: