You want to set up two paths on your navigation menu like so:
<?php
if (isset($_SESSION['username']))
{
?>
<a href="loggedinpage.php">PageName</a>
<?php
}
elseif (!isset($_SESSION['username']))
{
?>
<a href="login.php">Login</a>
<a href="bla.php">Page</a>
<?php
}
?>
So depending whether the $_SESSION[] is set or not.. Different anchors will be displayed.
Responding to comment
Try creating an array with the restricted files.. Example:
if (isset($_SESSION))
{
$Restrictions = array ("login.php", "index.php", "register.php");
if (in_array($_SERVER['REQUEST_URI'], $Restrictions ))
{
die ("You Must Login To View These Pages!"); //I use die and an include in my scripts, but this will be called when the user is navigating to a page such as login.php when they already have an active session
}
}
What the above will do, will utilize the $_SERVER Array for the requested URL, if the users session is active and the user tries to navigate to said filed in the array, they will be presented with a die
message. Ofcourse this can be changed to suit your needs.. and you can also do something similar using the same chunk, by restricting the users who are not logged in; from viewing the pages which you are required to be logged in.
For the re-direct
on your index.php, you could have something like this:
if (isset($_SESSION))
{
header("Location: member_area.php");
exit; // exit to stop the rest of your page (index.php for example) from processing.
}
This will re-direct the user to a page, if they have an active session.
Looking at your question; you want the user to be re-directed to a member_area if $_SESSION
is active.. Then use the last chunk under the name of "For the re-direct