CodeIgniter Forums
Fatal Error with Login session - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Fatal Error with Login session (/showthread.php?tid=60828)



Fatal Error with Login session - El Forum - 07-08-2014

[eluser]Unknown[/eluser]
Can anyone please help me, I am getting the following error message when someone has logged in and tried to click on their profile: Fatal error: c_login::checkSession() [<a href='c-login.checksession'>c-login.checksession</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition &quot;c_customer&quot; of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in /var/www/synced/mycactus/class/c_login.php on line 111

here is the c_login class

Code:
class c_login
{
/**
  * Checks login and stores the logged user into the c_login class/SESSION
  * @param $email String
  * @param $password String
  * @return boolean
  */
function check($email,$password,$isDebug=false)
{
  $user_id  = -1;
  $return  = false;
  $handler  = new c_customer_handler();
  
  if($email && $password)
  {
   $user_id = $handler->isUser(Array("email"=>$email,"password"=>$password), $isDebug);
   if($user_id)
   {
    $user = new c_customer();
    $user = $handler->loadCustomerByID($user_id,"SHORTVIEW",$isDebug);
    if($user->isValid())
    {
     c_login::setUser($user);
     $return = true;
    }
   }
   else
    $return = false;
  }
  else
   $return = false;
  
  return $return;
}

/**
  * Checks login against user class and stores the logged user into the c_login class/SESSION
  * @param $email String
  * @param $password String
  * @return boolean
  */
function checkUser($email,$password,$isDebug=false)
{
  $user_id  = -1;
  $return  = false;
  $handler  = new c_user_handler();
  $email = stripslashes($email);
  
  
  if($email && $password)
  {
   $user_id = $handler->isUser(Array("email"=>$email,"password"=>$password), $isDebug);
   if($user_id)
   {
    $user = new c_user();
    $user = $handler->loadUserByID($user_id,"SHORTVIEW",$isDebug);
    if($user->isValid())
    {
     c_login::setUser($user);
     $return = true;
    }
   }
   else
    $return = false;
  }
  else
   $return = false;
  
  return $return;
}

/**
  * Loads the full user out of the DB
  * @param $usage
  * @return unknown_type
  */
function loadDetails($usage="VIEW")
{
  $handler  = new c_customer_handler();  
  c_login::setUser( $handler->loadCustomerByID(c_login::user()->id, $usage) );
}

/**
  * Logs the user out and cleans the session up.
  */
function logout()
{
  return session_destroy();
}

/**
  * Checks if a user is logged in.
  * @return bool
  */

function checkSession()
{
  $return = false;
  
  if(session_id())
  {
   if(c_login::user()->isValid())
    $return = true;
  }
  
  return $return;
}

/**
  * Returns the logged user
  * @return c_customer
  */
function user()
{
  return !empty($_SESSION['login_user'])?$_SESSION['login_user']:new c_customer();
}

/**
  * Sets the logged user
  * @param $user c_customer
  */
function setUser($user)
{
  $_SESSION['login_user'] = $user;
}
}



Fatal Error with Login session - El Forum - 07-08-2014

[eluser]CroNiX[/eluser]
Could be several things.

In your user() method, does $_SESSION['login_user'] contain an instance of the c_customer class? Because you are trying to access a method, isValid(), in your checkSession() method which looks like it belongs to the c_customer class.

It all boils down to this line:
Code:
c_login::user()->isValid()



Fatal Error with Login session - El Forum - 07-09-2014

[eluser]Unknown[/eluser]
hi, thanks for your reply, I am very new to all this... this was working and suddenly stopped for some reason, could it be the PHP / APACHE versions on the server?


Fatal Error with Login session - El Forum - 07-10-2014

[eluser]CroNiX[/eluser]
"The script tried to execute a method or access a property of an incomplete object." Google that message. Most likely you aren't serializing the User class before storing it in session and/or not unserializing it when retrieving it.