Lassie Posted March 7, 2008 Share Posted March 7, 2008 I have some code to show a menu based on the user being logged in and also show the menu dependent on which page he is on. I am trying to combine the tests in one statement, but whilst user id is recognised the page checks are not. Can I write a statement this way? <?php // Display links based upon the login status. // Show secondary menu if user logged in and pages are not listed in statement. $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')) { ?> //do some js for menu <?php } ?> Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted March 7, 2008 Share Posted March 7, 2008 its a tad long... break it up into 2 or 3 if's Regards ACE Quote Link to comment Share on other sites More sharing options...
Lassie Posted March 7, 2008 Author Share Posted March 7, 2008 Right,I have broken it up but still not getting desired result. <?php if (isset($_SESSION['user_id']) { $currentPage=basename($_SERVER['SCRIPT_NAME']); } if ($currentPage!=strstr($_SERVER['PHP_SELF'], 'logout.php') && !strstr($_SERVER['PHP_SELF'], 'login.php') && !strstr($_SERVER['PHP_SELF'], 'view_account2.php')) { ?> //do some js for menu <?php } ?> i also thought of a different approach based on pathinfo as follows. This fails as well. <?php // Display links based upon the login status. // Show secondary menu if current dir is not /e_cart21/reg/. $path_parts = pathinfo($_SERVER['PHP_SELF']); //debug to check values echo $path_parts['dirname'], "\n<br />"; echo $path_parts['basename'], "\n"; echo $path_parts['extension'], "\n"; echo $path_parts['filename'], "\n"; $dir='/e_cart21/reg/'; if ($dir!=$path_parts['dirname']) { ?> //do some js for menu <?php } ?> Any thoughts much appreciated. Quote Link to comment Share on other sites More sharing options...
Lassie Posted March 7, 2008 Author Share Posted March 7, 2008 This works. Many thanks <?php if (isset($_SESSION['user_id']) { $currentPage=basename($_SERVER['SCRIPT_NAME']); if ($currentPage!=strstr($_SERVER['PHP_SELF'], 'logout.php') && !strstr($_SERVER['PHP_SELF'], 'login.php') && !strstr($_SERVER['PHP_SELF'], 'view_account2.php')) { ?> //do some js for menu <?php } } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.