I'm trying to get a link in my menu to change once the user logged in. Meaning that "My Page" is displayed, rather than "Log In". Now, the user can log in and log out. Yet the name/link will not change directly after the user logged in.
My code for the menu: (I use include('menu.php' on all sites. For flexibility of the code)
<div id="menu">
<ul>
<li><a href="index.php">Home</a></li>
<li><?php echo $mypage?></li>
<li><a href="community.html">Community</a></li>
<li><a href="media.html">Media</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
My code for the config.php:
<?php
session_start();
$mypage;
if(isset($_SESSION['name'])) {
$mypage = '<a href="mypage.php">My Page</a>';
}
else {
$mypage = '<a href="login.php">Log In</a>';
}
?>
Only when the user clicks on another menu the $mypage variable will update. I've tried refreshing the page with a header() function. But this only lead into a redirection-loop.
It would be great if someone could help me out.
EDIT
To clear some things up:
For a better understanding of the website: http://www.askmephilosophy.camilstaps.nl/ (The only thing that can be viewed (so far) are the 'Welcome' and 'Log In'. After a login you will be redirected to a mypage.php site. (this can also be accessed by just typing it after the name. */mypage.php)