I am trying to create a login page for a website. I have followed other guides/posts to get to this point, but I can't figure out why my logout button is not working.
The login functionality works as intended, but I cannot log out once logged in.
logout.php
<?php
//logout.php
session_start();
session_destroy();
header('Location: ' . $_SERVER['HTTP_REFERER']);
?>
index.php
<?php
ini_set("session.save_path", "/home/sessionData");
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width,
maximum-scale=1.0">
<meta charset="UTF-8">
<title>Index</title>
</head>
<body>
<?php
$form = '
<div class="form-container">
<form method="post"action="loginProcess.php">
<label>Username</label>
<input type="text" name="username" class="form-control" />
<br />
<label>Password</label>
<input type="password" name="password" class="form-control" />
<br />
<input type="submit" name="login" class="btn" value="Login" />
</form>
</div>
';
if(isset($_SESSION["username"])){
echo '<h3>Login Success, Welcome - '.$_SESSION["username"].'</h3>';
echo '<br /><br /><a href="logout.php">Logout</a>';
}
else{
echo $form;
}
?>
</div>
</div>
</body>
</html>
There is also a db connection script but I am pretty sure that is not the problem so I have left it out. Thanks for your help people, and let me know if you need me to clarify anything :)