I don't seem to understand how I can setup a session. I wrote this code:
<?php
require_once '../database/Database.php';
session_start();
$database = new Database('localhost', 'root', '');
if(isset($_POST['login'])){
$username = $_POST['username'];
$password = $_POST['password'];
if($database->login($username, $password)){
$loggedIn = $_SESSION['loggedIn'] = true;
header("location: ../dashboard/dashboard.php");
}
else{
echo "You've failed to login";
}
}
?>
<h2><!--<a href="../index.php" role="button" class="btn btn-info btn-circle"><i class="fa fa-home"></i></a>--><button class="btn btn-info btn-circle"><i class="fa fa-info"></i></button></h2>
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="information">
<h5>Additional Information</h5>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur malesuada, magna sed sagittis posuere, nulla massa vulputate erat, sed laoreet mi nisl id quam. Nunc sodales justo quis orci sagittis tincidunt. Aliquam consectetur, metus vel commodo molestie, dui nisl vulputate nunc, sit amet varius ex nisi a ante. Donec vitae semper enim. Nullam vulputate porttitor interdum. Phasellus vel vehicula ligula, sit amet consectetur nunc. Phasellus eget facilisis arcu, sed fringilla neque. Sed urna purus, dictum eu condimentum eu, egestas vitae lacus. Nam ultricies nec ligula quis consectetur. Suspendisse posuere nulla tortor, vel pulvinar nulla fermentum non. Sed quis nulla sed mi congue sollicitudin. Morbi consectetur mi quis mauris egestas commodo. Vivamus rhoncus vestibulum orci, quis aliquam velit convallis eget.
</p>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<img src="../assets/logo.png">
</div>
<div class="panel-body">
<form accept-charset="UTF-8" role="form" method="post">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="Username" name="username" type="text">
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" name="password" type="password">
</div>
<input class="btn btn-info btn-block" type="submit" name ="login" value="Login">
</fieldset>
</form>
</div>
</div>
</div>
<div class="col-md-4"></div>
</div>
</div>
Database function:
public function login($username, $password){
$this->connection = mysqli_connect($this->host, $this->dbUsername, $this->dbPassword, 'portal');
$query = mysqli_query($this->connection, "SELECT * FROM users WHERE password='$password' AND username='$username'");
if(mysqli_num_rows($query) != 0){
return true;
}
else{
return false;
}
}
I want to start a session when a user logs in and store this one. So when the user reloads the login page he/she's still logged in. Could anyone help me out