123456/V5 PO PHP/Sacha en Mats/inloggen.php
<?php
include('db.php'); //Verbinding maken met database
$gebruiker = $_POST['gebruiker'];
$ww = $_POST['ww'];
$isIngelogd = $_COOKIE['ingelogd'];
//console.log('hij is hier');
if ($isIngelogd == true){
header("location:tussenPagina.php");
//console.log('hij is hier');
}
if($_POST['posten']){ //als formulier verzonden
if(($ww == "Grimme" && $gebruiker == "Grimme")){
$mes = "je bent ingelogd";
$in_account = true;
header("location:tussenPagina.php");
setcookie('ingelogd', $in_account, time() + 60 * 2);
setcookie('account_naam', $gebruiker, time() + 60 * 5);
setcookie('account_wachtwoord', $ww, time() + 60 * 5);
}else if($ww && $gebruiker){
$mes = "Dit account bestaat niet";
$in_account = false;
}else {
$mes = "Er missen gegevens";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css?t=<?php echo time()?>">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
include('menubalk.php'); //Menubalk wordt opgenomen in bestand
if($in_account == true){
echo "<div style='color:green;font-size:1.2em'>$mes</div>";
}else if($in_account == false){
echo "<div style='color:red;font-size:1.2em'>$mes</div>";
}else if($ingelogd){
echo "<p>Je bent ingelogd.</p>";
}
else{
echo "<p>Je bent niet ingelogd.</p>";
}
?>
<div class="container-inlog">
<h2>Inloggen</h2>
<!--Formulier om gebruikersnaam en wachtwoord in te vullen-->
<form action="inloggen.php" method='post'>
<div class="inlog">
<p>Gebruiker:</p>
<input type='text' name='gebruiker' value='<?php echo $_COOKIE['account_naam'] ?>' placeholder="naam">
</div>
<div class="inlog">
<p>Wachtwoord:</p>
<input type='password' name='ww' value='<?php echo $_COOKIE['account_wachtwoord'] ?>' placeholder="wachtwoord"></div>
<div>
</br>
<input class="knop" type='submit' name='posten' value='Inloggen'>
</div>
</form>
</div>
</body>
</html>
Resultaat
Made by Thijs Aarnoudse