Log Out Process

Create Login with PHP and MySQL
Create Login with PHP and MySQL : Home
Algorithm
Sign Up Process
Log In Process
Log Out Process

Log Out
Log Out is the most easy step.All you have to do in unset the session.
log-out.php

<?php
session_start();
session_unset();
echo "Log Out successful";
?>

We will just add Log Out button in the log-in.php page
log-in.php

<?php
// Starting Session
session_start();
if(isset($_SESSION['user-email'])&&isset($_SESSION['user-name'])){
	echo "".$_SESSION['user-name'];
	echo "You are already Logged In<br> We promised you something here it is <br><b>Secret Data</b><br>";
	echo "<a href='b-page.php'>b-page</a><br>";
	echo "<a href='log-out.php'>Log Out</a>";
}
else{

// Checkinng if we have data from login form

if(isset($_POST['login-email'])&&isset($_POST['login-password'])){
	
	// Converting any special characters to entities and email to lowercase
	// So that same email is not considered different

	$email = htmlspecialchars(strtolower($_POST['login-email']));
	// Encrypting Password
	$password = md5($_POST['login-password']);

	$mysqli_object= new mysqli("localhost","","","db");
	$sql_login = "SELECT * FROM users WHERE email='".$email."' AND password='".$password."'";
	$result_login = $mysqli_object->query($sql_login);

	if($result_login->num_rows>0){
		$row=$result_login->fetch_assoc();
		//Using data from database
		// Storing data in database
		$_SESSION['user-email'] = $row['email'];
		$_SESSION['user-name'] = $row['name'];
		echo "Congrats ".$_SESSION['user-name'];
		echo "You are Logged In We promised you something here it is <br><b>Secret Data</b><br>";
		echo "<a href='b-page.php'>b-page</a><br>";
		echo "<a href='log-out.php'>Log Out</a>";
	}
	else{
		echo "Wrong Credentials <a href='log-in.php'>Login again</a>";
	}

	

}
// If POST data is not available i.e. form is not submitted
else{
	// Embedding HTML in PHP
	?>
<html>
<body>
<form method="post" action="log-in.php">
	<input type="text" name="login-email" placeholder="email" required="required">
	<input type="password" name="login-password" placeholder="password" required="required">
	<input type="submit" name="submit">
</form>

</body>
</html>
	<?php

}
}

?>

Login to Track Your Progress