i'm trying to make a login page using PDO but i'm getting this error,i have checked similar queries about this error here but they seem to be different from mine
Notice: Undefined variable: user in C:\xampp\htdocs\soft\index.php on line 5
Fatal error: Call to a member function is_loggedin() on null in C:\xampp\htdocs\soft\index.php on line 5
what causes the fatal error and how can i fix this because to my own understanding the code seems to be ok. this is my login page code
<?php
require_once 'dbconfig.php';
if($user->is_loggedin()!="")
{
$user->redirect('home.php');
}
if(isset($_POST['btn-login']))
{
$uname = $_POST['txt_uname_email'];
$umail = $_POST['txt_uname_email'];
$upass = $_POST['txt_password'];
if($user->login($uname,$umail,$upass))
{
$user->redirect('home.php');
}
else
{
$error = "Wrong Details !";
}
}
?>
this is the login function
public function is_loggedin()
{
global $db;
if(isset($_SESSION['user_session']))
{
return true;
}
}
and this is my user class
<?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($uname,$umail,$upass)
{
try
{
$stmt = $this->db->prepare("SELECT * FROM users WHERE user_name=:uname OR user_email=:umail LIMIT 1");
$stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() > 0)
{
if($userRow['user_pass']==MD5($upass))
{
$_SESSION['user_session'] = $userRow['user_id'];
return true;
}
else
{
return false;
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function is_loggedin()
{
global $db;
if(isset($_SESSION['user_session']))
{
return true;
}
}
public function redirect($url)
{
header("Location: $url");
}
public function logout()
{
session_destroy();
unset($_SESSION['user_session']);
return true;
}
}
?>
i'm just a newbie and i would like to know what im doing wrong thanks alot