2016-04-17 40 views
2

所以我一直在爲我的一個項目編寫代碼,我必須爲網站創建一個註冊和登錄系統,而且我現在很堅持。我把下面的「UserLogin.php」文件:調用PHP對象文件導致頁面不再加載

class UserLogin 
{ 
    private $username; 
    private $firstName; 
    private $lastName; 
    private $userid; 
    private $emailaddr; 
    private $error; 
    private $db; 
    private $hash; 
    private $salt; 
    private $password 

    public function __construct($user, $pass) 
    { 
     $this['username'] = $user; 
     $this['password'] = $pass; 
    } 

    function getError() 
    { 
     return $this->error; 
    } 



    public function userLogin($username, $password) 
    { 
     if (checkUser($username)) { 
      if (checkPass($password)) { 
       $_SESSION['memberName'] = $this['username']; 
       $_SESSION['fName'] = $this['firstName']; 
       $_SESSION['lName'] = $this['lastName']; 

       return true; 
      } 
     } else { 
      $error = "Invalid username/password"; 
     } 

    } 



    public function checkUser($username) 
    { 
     $mysqli = new mysqli('hostip', 'username', 'password', 'dbname', 3306); 
     $stmt = prepare($mysqli); 

     bind_param($stmt, "s", $username); 
     execute($stmt); 
     bind_result($stmt, $this['user_id'], $this['username'], $this['salt'], $this['hash']); 

     if (isset(fetch($stmt))) { 
      return false; 
     } 
     return true; 
    } 



    public function checkPass($password) 
    { 
     return hash_equals($this['hash'], crypt($password, $this['hash'])); 
     //return (hash_hmac("sha256", $password, $this['salt']) === $this['hash']); 
    } 

從另一個文件中,用戶輸入自己的用戶名和密碼,然後按回車鍵後:

include 'UserLogin.php'; 
$username = $_GET["username"]; 
$password = $_GET["pwd"]; 
$usersession = new UserLogin($username, $password); 
echo "created"; 

$var = $usersession->userLogin($username, $password); 
if ($var){ 
    echo "Verified"; 
} 

到目前爲止,我還沒有能夠找到任何錯誤,但我的網站沒有完成加載後登錄按鈕被擊中。任何幫助將不勝感激。另外請注意,我在mysqli變量中檢查了我的實際數據庫信息。

回答

0

你錯過了分號($password後),isset()不能被稱爲一個功能,您不能使用類作爲一個數組$this['username'],你必須稱之爲$this->username
另外你的userLogin()方法返回true,如果一切正常,但如果用戶/密碼錯誤則什麼也不做。

唯一的真正的建議是看錯誤日誌並逐一解決它們。

相關問題