Results 1 to 5 of 5

Thread: How to show menu based on current page selection

  1. #1
    Join Date
    Feb 2008
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to show menu based on current page selection

    I need to display a secondary menu when a user is logged in but not show that menu on certain pages.The restricted pages are all in 1 folder ./reg/
    I would like to include all the conditions in an if statement.
    At present the test for the user session works but not the pages.
    Can anyone help please.
    Code:
    <?php
    // Display links based upon the login status.
    				// Show LOGIN links if this is the LOGOUT page.
    					
    						$currentPage=basename($_SERVER['SCRIPT_NAME']);
    						if (isset($_SESSION['user_id']) AND (substr($_SERVER['PHP_SELF'], -10) != 'logout.php'||'login.php'||'view-account2.php'))
    						{
    											
    						?>
    //javascript goes here for menu
    <php
    }
    ?>

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Instead of this:

    Code:
    <?php
    // Display links based upon the login status.
    				// Show LOGIN links if this is the LOGOUT page.
    					
    						$currentPage=basename($_SERVER['SCRIPT_NAME']);
    						if (isset($_SESSION['user_id']) AND (substr($_SERVER['PHP_SELF'], -10) != 'logout.php'||'login.php'||'view-account2.php'))
    						{
    											
    						?>
    //javascript goes here for menu
    <php
    }
    ?>
    Try this:

    Code:
    <?php
    // Display links based upon the login status.
    				// Show LOGIN links if this is the LOGOUT page.
    					
    						$currentPage=basename($_SERVER['SCRIPT_NAME']);
    						if (isset($_SESSION['user_id']) AND !strstr($_SERVER['PHP_SELF'], 'logout.php') || !strstr($_SERVER['PHP_SELF'], 'login.php') || !strstr($_SERVER['PHP_SELF'], 'view-account2.php'))
    						{
    											
    						?>
    //javascript goes here for menu
    <php
    }
    ?>
    Not tested, but hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Feb 2008
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks. Tried it but still get menu appearing on pages that it shouldn't.
    Will the if statement stop if the user sesion test returns true and threrefore ignore the rest of the statement?

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Will the if statement stop if the user sesion test returns true and threrefore ignore the rest of the statement?
    Only if the session variable "user_id" is not set.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Are you destroying the session before you look at the pages it "shouldn't" be on?
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •