2010-11-20 138 views
0

我在我的項目中使用usercake作爲用戶管理模塊。這是我的第一個PHP項目,我仍然在學習。我建立了數據庫和usercake項目,但我不斷收到此錯誤 -如何解決此php錯誤

注意:試圖讓非對象的屬性在C:\ WAMP \ WWW \ userCake \型號\上線170 funcs.user.php

注意:試圖讓非對象的屬性在C:\ WAMP \ WWW \ userCake \型號\ funcs.user.php上線172

而這個錯誤只有當沒有抓到用戶登錄到系統。一旦用戶登錄,我不會再遇到這個錯誤。代碼負責是 -

function isUserLoggedIn() 
{ 
    global $loggedInUser,$db,$db_table_prefix; 

    $sql = "SELECT User_ID, 
      Password 
      FROM ".$db_table_prefix."Users 
      WHERE 
      User_ID = '".$db->sql_escape($loggedInUser->user_id)."' //line 170 
      AND 
      Password = '".$db->sql_escape($loggedInUser->hash_pw)."' // line 172 
      AND 
      Active = 1 
      LIMIT 1"; 

    $sql = mysql_num_rows($sql); 

    if($loggedInUser == NULL) 
    { 
     return false; 
    } 
    else 
    { 
     //Query the database to ensure they haven't been removed or possibly banned? 
     if(returns_result($sql) > 0) 
     { 
       return true; 
     } 
     else 
     { 
      //No result returned kill the user session, user banned or deleted 
      $loggedInUser->userLogOut(); 

      return false; 
     } 
    } 
} 

我試圖解決這個與我有限的知識的PHP,但無法。我猜這個錯誤類似於未在.net中設置爲對象實例的對象引用。我對嗎?如果不是,是什麼導致了這個錯誤?

我該如何解決這個問題?

回答

1

我想第一次用戶沒有登錄,引用爲空,所以在第170行,$db->sql_escape($loggedInUser->user_id).導致類似空引用的東西。嘗試在代碼停止提領,如果用戶是空的開始移動

if($loggedInUser == NULL) { return false; }

0

我懷疑只要用戶沒有登錄,全局變量$loggedInUser就是空的。所以通過SQL使用它來檢測用戶是否登錄...這是一條蛇咬自己的尾巴。

如果$loggedInUser爲空,那麼您可能希望返回前面的

1
function isUserLoggedIn() { 
    global $loggedInUser, $db, $db_table_prefix; 

    if ($loggedInUser == NULL) { return false; } 
    else { 
     $sql = "SELECT User_ID, 
       Password 
       FROM " . $db_table_prefix . "Users 
       WHERE 
       User_ID = '" . $db->sql_escape($loggedInUser->user_id) . "' 
       AND 
       Password = '" . $db->sql_escape($loggedInUser->hash_pw) . "' 
       AND 
       Active = 1 
       LIMIT 1"; 

     //Query the database to ensure they haven't been removed or possibly banned? 
     if (returns_result($sql) > 0) { return true; } 
     else { 
      //No result returned kill the user session, user banned or deleted 
      $loggedInUser->userLogOut(); 

      return false; 
     } 
    } 
} 

用此替換功能。 SQL語句不應該被設定,直到它檢查後,如果$與loggedInUser是空..

1

我有完全相同的問題,

看來我有我自己的數據庫連接whice被的userCake連接是後開始這明顯地忽略了userCake連接,使得它不可能實現sql_escape。

嘗試在userCake包含後禁用任何數據庫連接。

順便說一句,你還應該在userCake包含之前刪除任何session_start()。這將導致會話中的__php_incomplete_class錯誤