0

im arround this issue for a few days, and i cant get any solution.

I have two hosting servers. Lets call them pt and net.

If i instal this website on net, its all okay, but if i move it to pt, it gives me the following error:

Fatal error: Cannot use object of type backoffice as array in /nfs/c01/h13/mnt/####/domains/mysite.pt/html/backoffice/topo.php on line 77

This only happen on this server. On local host and on net server its all okay.

The line 77 has:

<?php echo $_SESSION['backoffice']['nome']?>

If i var_dump the $_SESSION['backoffice'] it gives me this on the different servers:

On localhost and net:

array (size=4)
  'id' => string '1' (length=1)
  'nivel' => string '2' (length=1)
  'nome' => string 'MyName' (length=9)
  'email' => string 'email@email.com' (length=23)

On pt server gives me this:

object(__PHP_Incomplete_Class)#4 (2) { ["__PHP_Incomplete_Class_Name"]=> string(10) "backoffice" ["db"]=> object(__PHP_Incomplete_Class)#2 (6) { ["__PHP_Incomplete_Class_Name"]=> string(2) "db" ["descriptor"]=> int(0) ["db"]=> string(22) "name_of_database_here" ["query"]=> int(0) ["result"]=> array(22) { [0]=> array(5) { ["id"]=> string(2) "16" ["titulo"]=> string(13) "Administração" ["descricao"]=> string(39) "Lorem ipsum dolor sit amet, consectetur" ["estado"]=> string(1) "1" ["slug"]=> string(13) "administracao" }

i've checked on the both servers the php.ini and they are identical.

The class that i have to create the array Backoffice is:

function login($email, $password, $session) {
        $email = filter_var(mysql_real_escape_string($email), FILTER_SANITIZE_EMAIL);
        $password = filter_var(mysql_real_escape_string(md5($password.SALT)), FILTER_SANITIZE_STRING);
        $session = filter_var(mysql_real_escape_string($session), FILTER_SANITIZE_NUMBER_INT);
        $query="SELECT id, nome, email, nivel, hash FROM admin WHERE email='$email' AND password='$password' LIMIT 1";
        $login=$this->db->opencursor($query);
        if ($login) {
            $_SESSION['backoffice']['id']=$login[0]['id'];
            $_SESSION['backoffice']['nivel']=$login[0]['nivel'];
            $_SESSION['backoffice']['nome']=$login[0]['nome'];
            $_SESSION['backoffice']['email']=$login[0]['email'];
            if ($session) setcookie("backoffice", $login[0]['hash'], time()+(7*24*60*60), "/");
            else setcookie("backoffice", '', time()-3600, "/");
            $this->saveLog($login[0]['id'],$_SERVER['REMOTE_ADDR']);
            return true;
        }
    else {
        $this->ban($_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_TIME']);
        return false;
    }
}

And, i cant find the error on this -- Help.

Thankyou

  • UPDATE 1

Amal Murali - This post is not duplicated, i've searched for a issue like this and i didnt found any solution that fits.

Jim, your solution helped. The array seems normal when i login and load the page for the first time.

i have a function that checks if the user has cookies to stay logged in, and i added that piece of code to. Now my function looks like:

if ($login) {
        **$_SESSION['backoffice'] = array();**
        $_SESSION['backoffice']['id']=$login[0]['id'];
        $_SESSION['backoffice']['nivel']=$login[0]['nivel'];
        $_SESSION['backoffice']['nome']=$login[0]['nome'];
        $_SESSION['backoffice']['email']=$login[0]['email'];
        if ($session) setcookie("backoffice", $login[0]['hash'], time()+(7*24*60*60), "/");
        else setcookie("backoffice", '', time()-3600, "/");
        $this->gravaLog($login[0]['id'],$_SERVER['REMOTE_ADDR']);
        return true;
    }

but, if i reload the page, the array returns to the same mess.

user3306164
  • 3
  • 1
  • 3
  • possible duplicate of [\_\_PHP\_Incomplete\_Class\_Name wrong](http://stackoverflow.com/questions/7272813/php-incomplete-class-name-wrong) – Amal Murali Feb 13 '14 at 13:39
  • 1
    Does it make a difference if you explicitly set `backoffice` as an array before assigning to it? `$_SESSION['backoffice'] = array();` – Jim Feb 13 '14 at 13:45
  • this have worked when we log on the first time. After the reload, it stays the same. See the updated question please – user3306164 Feb 13 '14 at 16:39
  • I found a solution that works. I've edited the php.ini : register_globals = 0 this worked for me. Found this solution here: http://forum.imasters.com.br/topic/405391-resolvidoerro-cannot-use-object-of-type-as-array/ – user3306164 Feb 13 '14 at 20:25

0 Answers0