Need variable navigation, in PHP.

I have some navigation that I wan to vary depending on if Im signed in or signed out.  In my case:

Iif Im signed in I want the navigation to be as follows:

"Help | Sign Out"

If Im signed out I want the navigation to be as follows:

"Help | Sign In"

In the future I will add more navigation to both.
a204801Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nplibCommented:
Are you using Sessions?
Cookies?
How does you page know when a user is logged in.

if you are using sessions
if ($_SESSION['user'])
{
      echo "logged in";
}
else
{
     echo "logged out";
}
0
steezyCommented:
Let's say that when someone logs in, they have a session variable set named $_SESSION['something'].

<?php if ($_SESSION['something']) { echo "Sign Out"; } else { echo "Sign In"; } ?>
0
Loganathan NatarajanLAMP DeveloperCommented:
please maintain those menus & values in some include files  or config.php file configuration values. ....like ...

then you just include it as per login status or based on your need...

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

a204801Author Commented:
logudotcom,

What about maintianing two differnt nav files.  Just calling one if your logged in and one if your logged out.  the questions is.  What does the PHP look like for this?
0
Loganathan NatarajanLAMP DeveloperCommented:
What does the PHP look like for this?

>> maintain in single include file and check the logged status condition to those menus to be enabled and have the nav menus... ... need not have two files.,

got it..? thatz PHP.. we can check dynamically in those pages.,
0
Loganathan NatarajanLAMP DeveloperCommented:
check_include.php
==============

<?php

if (isset($_SESSION["user"])) {

   echo ""Help | Sign Out   | menu 2 | menu 3"";

} else {

echo "Help | Sign In";

}

?>

so, you can even design the html code and separate it..,
0
nplibCommented:
@logudotcom:

how is that different then my solution?
0
a204801Author Commented:
Guys,

I wish I was better at PHP, and Im trying, but I really cant get this tow work.

I have an include thats contains the navigation.  In that file I only have the following:

<div class="brandingHeaderUA" align="right"><div class="headerNav"><a href="#">Help</a> | <a href="#">Sign Out</a> </div></div>

Now, how do I incorporate the above code?  How do I make it work is prob. the most direct question.

Thanks, Mac
0
nplibCommented:
make two navigation include files

if ($_SESSION['user'])
{
      include("file1.php"); //logout
}
else
{
     include("file2.php"); //login
}
0
a204801Author Commented:
How does it know if your logged in/out?  I added the code and created the two includes with the different navigation elements.  Doesnt seem take the though.  It picks up the right include when logged in, but it doesnt switch once you logout.  Just the same navigation.

Here is how I have the code:

<?php

if ($_SESSION['user'])
{
      include("loggedout.php"); //logout
}
else
{
     include("loggedin.php"); //login
}

?>

Do I have to do something with the 'user' part of the session?
0
nplibCommented:
when you user successfully logs in you need two things

at the very top of EVERY page that will read session variables
<?php
session_start();


then after the user logs in,
$_SESSION['user'] = $username;

then

<?php
session_start();
if ($_SESSION['user'])
{
      include("loggedout.php"); //logout
}
else
{
     include("loggedin.php"); //login
}

?>
0
Loganathan NatarajanLAMP DeveloperCommented:
@nplib

earlier, you did not clearly explained to him what is needed...that menu part.,
0
a204801Author Commented:
Let me just clarify.

Im supposed to add this to every page:

<?php
session_start();
?>

Im not sure where this goes:
$_SESSION['user'] = $username;

Does that go within the PHP tags or does it have to be seperate?

0
Loganathan NatarajanLAMP DeveloperCommented:
when you include this <?php
session_start();
?>

in each page... then you can include session variable used files could be well included or used... no issues..


Does that go within the PHP tags or does it have to be seperate?

>> it will be available int he variable scope .. thatz called SESSION .. as global scope
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nplibCommented:
post your code where the user authenticates.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.