I have the following HTML code. I have 2 php files: login.php and logout.php. When any user first comes to my page, I would like him to see the login link. After clicking lo
I am assuming you are using a session to check whether user logged in or not. If not, create a session variable and set once logged in. Clear the session variable on log out. So you can check
if(isset($_SESSION['logged_in'])){
//your logout link
}else{
//your login link
}
<?php
if ($signout)
{
echo "<li><a href=logout.php >Logout</a></li>";
}
else
{
echo "<li><a href=register.php >Register</a></li>";
echo "<li><a href=login.php >Login</a></li>";
}
?>
Try this.
You need to set a variable $logged_user
to identify whether the user is logged in or not
<header class="group">
<nav class="group">
<ul>
<?php if ($logged_user) { ?>
<li><a href="logout.php" title="">Logout</a></li>
<?php } else { ?>
<li><a href="register.php" title="">Register</a></li>
<li><a href="login.php" title="">Login</a></li>
<?php } ?>
</ul>
</nav>
<?php
if(isset($_SESSION['user_id'])) {
echo "<form method='POST' action='".userLogout()."'>"; ?>
<li><button type="submit" name="userlogout" id="logout-button" class="button-logout">LOGOUT</button></li>
<?php } else { ?>
<li><a href="login">LOGIN</a></li>
</form>
<?php }
?>