Hello,
I am having some issues of my session class i am trying to develop i am trying to learn how to create my own session class for login and logout and other details only issue is that im not sure what i am doing wrong to check either i am logged in or not on the page that requires people to login
not sure if my class i have created so far is the way i should be going about it ive made an attempt on my class but not sure on how to check if the user has logged in without doing OOP Progrmaming
My class is the following
class Sessions extends BCCMS
{
//
private $LoggedIn = false;
public $user_id;
public $userExists = false;
public $passMatch = false;
public $con;
function _construct()
{
}
public function CheckLogin()
{
if($this->LoggedIn = true)
{
return $this->LoggedIn = true;
}
else
{
return $this->LoggedIn = false;
}
//
}//
public function ConnectDB($dbhost,$dbuser,$pass,$dbname)
{
//
$this->con=mysqli_connect($dbhost,$dbuser,$pass,$dbname);
if(!$this->con)
{
die("Unable to connect to MYSQL Database on ".$dbhost."");
}
else
{
//echo "Connected to DB".$dbname."";
}
//
}
//
public function is_logged_in()
{
return $this->LoggedIn;
}
public function login($user,$password)
{
//
$msg_pass="";
$msg_user="";
$user = mysqli_real_escape_string($this->con,stripslashes(trim($user)));
$password = mysqli_real_escape_string($this->con,stripslashes(trim($password)));
$Q=$this->Query("SELECT * FROM members WHERE username='".$user."' AND Password='".$password."'");
echo $Q;
if($this->LoggedIn = true)
{
$this->SuccessLogin($user);
}
else
{
//
if($this->UsernameMatch($user) == true)
{
if($this->PasswordMatch($password) == true)
{
$this->SuccessLogin($user);
}
else
{
echo "Your Username matches but your password does not match the username in the database";
}
}
else
{
echo "Username Does not match";
}
//
}
}
public function logout()
{
unset($_SESSION['user']);
unset($this->user_id);
$this->LoggedIn = false;
}
public function UsernameMatch($user)
{
//
$this->Query("SELECT username FROM members WHERE username='".$user."'");
$count=mysqli_num_rows($rs);
if($count=1)
{
return $this->userExists = true;
}
else
{
return $this->userExists = false;
}
//
}
//
public function PasswordMatch($user)
{
//
$this->Query("SELECT password FROM members WHERE username='".$user."'");
$count=mysqli_num_rows($rs);
if($count=1)
{
return $this->passMatch = true;
}
else
{
return $this->passMatch = false;
}
//
}
//
private function SuccessLogin($user)
{
//
$_SESSION['user'] = $user;
$this->LoggedIn = true;
echo "Logged in";
//
}
//
}
Is this correct anything else i can do to improve it?