Log in

View Full Version : How to show menu based on current page selection



fodo
03-06-2008, 05:47 PM
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.


<?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
}
?>

thetestingsite
03-06-2008, 05:57 PM
Instead of this:



<?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:



<?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.

fodo
03-06-2008, 06:03 PM
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?

thetestingsite
03-06-2008, 06:07 PM
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.

alexjewell
03-07-2008, 01:41 PM
Are you destroying the session before you look at the pages it "shouldn't" be on?