Jump to content

Problem with if statement


Lassie

Recommended Posts

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

					}
					?>

Link to comment
https://forums.phpfreaks.com/topic/94866-problem-with-if-statement/
Share on other sites

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.

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



Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.