I have the following code that logs in a user and i want to be able to use the logout function. But for some reason when i go to logout.php it gives me the following error:
Notice: Undefined variable: user in /var/www/www.test.com/logout.php on line 2
Fatal error: Call to a member function logout() on null in /var/www/www.test.com/logout.php on line 2
I have the following code for my index.php
<?php
require_once(ROOT . 'include/dbconfig.php');
if($user->is_loggedin()!="")
{
    if($_SESSION['type'] = "Admin"){
        $user->redirect(DOMAIN . 'admin/index.php');    
    }else{
        $user->redirect(DOMAIN . 'customer/index.php');
    }
}
if(isset($_POST['btn-login']))
{
    $username = $_POST['username'];
    $password = $_POST['password'];
    if($user->login($username,$password))
    {
        if($_SESSION['type'] = "Admin"){
            $user->redirect(DOMAIN . 'admin/index.php');    
        }else{
            $user->redirect(DOMAIN . 'customer/index.php');
        }
    }
    else
    {
        $error = "There was an error with the login";
    }
}else{
?>
<html lang="en" class="body-full-height">
    <body>
    <form action="index.php" method="post">
        <table>
        <?php
            if(isset($error))
                {
                 ?>
                    <tr>
                        <td><?php echo $error; ?></td>              
                 <?php
                }
        ?>
            <tr>
                <td>User Name</td>
                <td>Password</td>
            </tr>
            <tr>
                <td><input type="text" name"username"></td>
                <td><input type="text" name"password"></td>
            </tr>
            <tr>
                <td colspan="2"><button name="btn-login" value="Login"></td>
            </tr>
        </table>
    </form>    
    </body>
</html>
<?php
}
?>
Below is the code for the class.user.php
<?php
class USER
{
    private $db;
    function __construct($DB_con)
    {
        $this->db = $DB_con;
    }
    public function register($fname,$lname,$uname,$umail,$upass)
    {
        try
        {
            $new_password = MD5($upass);
            $stmt = $this->db->prepare("INSERT INTO users(user_name,user_email,user_pass) 
                                                       VALUES(:uname, :umail, :upass)");
            $stmt->bindparam(":uname", $uname);
            $stmt->bindparam(":umail", $umail);
            $stmt->bindparam(":upass", $new_password);                                        
            $stmt->execute();   
            return $stmt;   
        }
        catch(PDOException $e)
        {
            echo $e->getMessage();
        }               
    }
    public function login($username,$password)
    {
        try
        {
            $stmt = $this->db->prepare("SELECT * FROM users WHERE username=:username 
                                        AND password=:password 
                                        AND status = 'active' LIMIT 1");
            $stmt->execute(array(':username'=>$username, ':password'=>$password));
            $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
            if($stmt->rowCount() > 0)
            {
                if($userRow['isadmin']){
                    $_SESSION['type']  = "Admin";
                    $_SESSION['fname'] = $userRow['fname'];
                    $_SESSION['uid']   = $userRow['uid'];
                    return true;
                }else{
                    $_SESSION['type']  = "Customer";
                    $_SESSION['fname'] = $userRow['fname'];
                    $_SESSION['uid']   = $userRow['uid'];
                    return true;
                }
            }else{
                return false;   
            }
        }
        catch(PDOException $e)
        {
            echo $e->getMessage();
        }
    }
    public function is_loggedin()
    {
        if(isset($_SESSION['uid']))
        {
            return true;
        }
    }
    public function redirect($url)
    {
        header("Location: $url");
    }
    public function logout()
    {
        session_destroy();
        unset($_SESSION['uid']);
        return true;
    }
}
?>
Below is the code for the logout.php
<?php
$user->logout();
?>
