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

Link to comment
Share on other sites

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



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.