Jump to content

CMS Tutorial Series by Ben - Quick Q


Fjorko

Recommended Posts

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 !

Link to comment
Share on other sites

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 !

Link to comment
Share on other sites

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

}


?>

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...