I'm trying to figure out how to implement a Log Out button into my code, but can't seem to figure out how to do it. Here is the code for my Log In page and Index page.
Index Page HTML
<?php
include("connectDatabase.php");
include("products.php");
?>
<?php
require "logincheck.php";
?>
<html>
<head>
<br><br>
<a href="resetPassword.php">Reset Password Page</a><br><br>
<a href="login.php">Login Page</a><br><br>
<a href="forgotPassword.php">Forgot Password Page</a><br><br>
<a href="logincheck.php">Login Check Page</a><br><br>
<a href="register.php">Register Page</a><br><br>
</head>
<body>
<h1> Small IT Business <h1>
Welcome <?php echo $_SESSION["email"] ?>.
</body>
</html>
Login In Page PHP
<?php
session_start();
if (isset ($_SESSION["email"]) && isset($_SESSION["loggedIn"])) {
header("Location: index.php");
exit();
}
if(isset($_POST["logIn"])) {
$connection = new mysqli("localhost", "root", "", "membershipsystem");
$email = $connection->real_escape_string($_POST["email"]);
$password = sha1($connection->real_escape_string($_POST["password"]));
$data = $connection->query("SELECT firstName FROM users WHERE
email='$email' AND '$password'");
if($data->num_rows > 0) {
$_SESSION["email"] = $email;
$_SESSION["loggedIn"] = 1;
header("Location: index.php");
exit();
}else{
echo "Please check your imputs!";
}
}
?>
<html>
<body>
<form actions="login.php" method="post">
<input type="text" name="email" placeholder="Email"/><br />
<input type="password" name="password" placeholder="Password"/><br
/>
<input type="submit" value="Log In" name="logIn" />
</body>
</html>