I'm trying to show the login form to visitors only and hide it when user is logged in. I've seen similar question here but I couldn't get the answer. In the current code I get the Login form which is included from another page and also an error " Undefined index: UserName". So how can I define it?
<?php session_start() ?>
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<meta charset="utf-8"/>
<link rel="stylesheet" href="IndexStyle.css"/>
<meta name="viewport" content="width= device-width, intial-scale=1.0">
</head>
<body class="body">
<header class="MainHeader">
<img src="images/header-image-5.jpg">
<nav><ul>
<li class="active"><a href="index.php">Home</a></li>
<li><a href="Product.php">Products</a></li>
<li><a href="AboutUs.php">About Us</a></li>
<li><a href="ContactUs.php">Contact Us</a></li>
<div id="AdminP">
<li><a href="AdminPanel.php">Admin Panel</a></li>
</div>
</ul>
</header>
<div class="MainBody">
<p>This is Mainbody
</p>
</div>
<aside class="SideBar">
<div class="login">
<?php
if($_SESSION['UserName'] == "") {
include 'Form.php';
} else {
echo "Logged in";
}
?>
</div>
<p> </p>
</aside>
<Footer class="Footer">
<p>Copyrights reserved
</p>
</Footer>
</body>
</html>