Black Belt
- Join Date:
- Jul 2005
- Location:
- Upstate NY
- Posts:
- 21,874
- Plugin Contributions:
- 8
Post #21 by gjh42
These "multiple double negative" logic situations can be very tricky to work out correctly. I'll pick this apart bit by bit and see whether it is right as is or needs tweaking.```php
<?php for ($i=1, $n=sizeof($var_linksList); $i<=$n; $i++) { if (!($var_linksList[$i]['name'] == 'Login' and $_SESSION['customer_id']) or !($var_linksList[$i]['name'] == 'Logoff' and !$_SESSION['customer_id'])) { ?><a href="<?php echo $var_linksList[$i]['link']; ?>"><?php echo $var_linksList[$i]['name']; ?></a><?php echo ($i < $n ? EZPAGES_SEPARATOR_HEADER : '') . "\n"; ?>
<?php } //end if
} // end FOR loop ?>
If this is the login link and customer is logged in, the first section is true. "True" gives a false result for this part due to the leading "not" (!).
If this is the logoff link and customer is not logged in, the second section is true. Again, "true" gives a false result for this part due to the leading "not" (!).
At least one of these sections must result in true for the overall test to be true (the "or" linking them).
Anything but login link and logged in makes the first section false, giving a "true" result for it.
Anything but logoff link and not logged in makes the second section false, giving a "true" result for it.
The current link can't be both login and logoff, so at least one of these has to result in true, making the overall test always true.
So it needs an "and" instead of "or" joining the sections. Running through it again that way, we get:
Both of these sections must result in true for the overall test to be true (the "and" linking them).
Anything but login link and logged in makes the first section false, giving a "true" result for it.
Anything but logoff link and not logged in makes the second section false, giving a "true" result for it.
Login link and logged in makes the first section true, giving a "false" result and thus a false overall test (hiding the login link).
Logoff link and not logged in makes the second section true, giving a "false" result and thus a false overall test (hiding the logoff link).
So that's it: change the "or" to "and" in the middle of the if() statement.