[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

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.
0
a204801
Asked:
a204801
  • 5
  • 5
  • 4
  • +1
1 Solution
 
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
 
nplibCommented:
post your code where the user authenticates.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 5
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now