Fjorko Posted July 14, 2011 Report Share Posted July 14, 2011 I followed the CMS Tutorial to the "T", and have everything exactly as Ben explained. At the end of Video 14, where the login system part of the tutorial comes to an end, and where you log in as admin to test everything, I have an error that comes up and I cannot understand why. I compared my Code to Ben's and it all looks exactly the same. I even checked the source code files and it's the same there too.... I'm running that lastest version of WAMP, so that's OK. The login form and everything works fine except I get this message when I try to log in as admin : Fatal error: Call to undefined method Auth::checkLoginStatus() in D:\wamp\www\LOGIN\members.php on line 6 I checked and the new Auth() object is defined in the init.php file. The class is created in m-auth.php ( and I double checked everything in there ), the method ( checkLoginStatus) is correct, and the same method is called correctly in the login.php file if($Auth->checkLoginStstus() == FALSE) So I'm at a lost as to what the issue is...I'm sure it's something very simple... Ben can you guide me here please ? I cannot continue with the series if i cannot get this fixed.... Thanks ! Quote Link to comment Share on other sites More sharing options...
falkencreative Posted July 14, 2011 Report Share Posted July 14, 2011 Can you post the code to members.php and m-auth.php? Quote Link to comment Share on other sites More sharing options...
Fjorko Posted July 14, 2011 Author Report Share Posted July 14, 2011 Can you post the code to members.php and m-auth.php? Members.php : <?php include("includes/init.php"); //check authorisation if($Auth->checkLoginStatus() == FALSE) { $Template->setAlert("Unauthorised!","error"); $Template->redirect("login.php"); } else { $Template->load("views/v_members.php"); } ?> m_auth.php <?php /* Authorisation Class Deals with Authentication Tasks *******************************/ class Auth { private $salt = "4JHGBF5"; /* Constructor */ function __Construct() { } /* Functions ***********/ function validateLogin($user, $pass) { global $Database; //allows this function to have access to the $Database variable defined in database.php //create query if($stmt = $Database->prepare("SELECT * FROM users WHERE username = ? AND password = ?")) { $stmt->bind_param("ss",$user,md5($pass.$this->salt)); $stmt->execute(); $stmt->store_result(); //check num rows returned if($stmt->num_rows > 0) { //success $stmt->close(); return TRUE; } else { //fail $stmt->close(); return FALSE; } } else { die("ERROR: Could not prepare MYSQLi statement"); } function checkLoginStatus() { if(isset($_SESSION["loggedin"])) { return TRUE; } else { return FALSE; } } function logout() { session_destroy(); session_start(); } } } ?> Note - I use a slightly different SALT than yours, so my value will differ ! Quote Link to comment Share on other sites More sharing options...
falkencreative Posted July 14, 2011 Report Share Posted July 14, 2011 Your "function validateLogin($user, $pass)" function doesn't close properly. You have the closing "}" after checkLoginStatus() and logout() which is causing issues. You need this instead: <?php /* Authorisation Class Deals with Authentication Tasks *******************************/ class Auth { private $salt = "4JHGBF5"; /* Constructor */ function __Construct() { } /* Functions ***********/ function validateLogin($user, $pass) { global $Database; //allows this function to have access to the $Database variable defined in database.php //create query if($stmt = $Database->prepare("SELECT * FROM users WHERE username = ? AND password = ?")) { $stmt->bind_param("ss",$user,md5($pass.$this->salt)); $stmt->execute(); $stmt->store_result(); //check num rows returned if($stmt->num_rows > 0) { //success $stmt->close(); return TRUE; } else { //fail $stmt->close(); return FALSE; } } else { die("ERROR: Could not prepare MYSQLi statement"); } } // add this function checkLoginStatus() { if(isset($_SESSION["loggedin"])) { return TRUE; } else { return FALSE; } } function logout() { session_destroy(); session_start(); } // } remove this } ?> Quote Link to comment Share on other sites More sharing options...
Fjorko Posted July 14, 2011 Author Report Share Posted July 14, 2011 LOL ! No Way !!!!!! Hahahahahahahahaha - What a plonker am I !!!!! So sorry to have wasted your time ! PS : It's working just fine now ! Thanks so much ! Quote Link to comment Share on other sites More sharing options...
falkencreative Posted July 14, 2011 Report Share Posted July 14, 2011 No worries. This is the reason I like using a text editor with syntax highlighting and ensuring I tab in my code to indicate hierarchy... It helps to catch these sort of errors. Glad that took care of it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.