have click login button twice to post on welcome page
login.php
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="assets/css/bootstrap.css">
<title>Document</title>
</head>
<body>
<section class="mt-5">
<div class="container">
<div class="row">
<div class="col-3"></div>
<div class="col-6">
<form action="welcome.php" method="post">
<input type="text" name="txtName" class="form-control mb-3">
<input type="password" name="txtPass" class="form-control mb-3">
<input type="submit" value="Log in" name="btnLogin" class="btn btn-block btn-success">
</form>
</div>
<div class="col-3"></div>
</div>
</div>
</section>
<?php
if(isset($_POST["btnLogout"])){
unset($_SESSION["name"]);
}
?>
</body>
</html>
welcome.php
<?php
session_start();
if(isset($_SESSION["name"])){
echo $_SESSION["name"];
}
else{
header("location:login.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="login.php" method="post">
<input type="submit" value="Log Out" name="btnLogout">
</form>
<?php
if(isset($_POST["btnLogin"])){
$_SESSION["name"]=$_POST["txtName"];
$_SESSION["pass"]=$_POST["txtPass"];
}
?>
</body>
</html>