You have to carefully think through the logic that you're trying to express.
Right now, your logic says "If the subdomain isn't 'www' or the subdomain isn't 'nosub'". If either one of those is true, the code will be executed.
Let's try some test cases on this:
- nosub: this isn't "www", so that condition is true, execute the code
- random: this isn't "www" or "nosub", so both conditions are true, execute the code
- www: this isn't "nosub", so that condition is true, execute the code
Basically what you've done is made it so everything will be true. What you're actually trying to express is "The subdomain isn't 'www' AND it isn't 'nosub'". That is, if it's NEITHER of those, you want to execute the code.
The correct if statement would be: if ($subd != 'nosub' && $subd != 'www')
.
If you have trouble with this, it may be better to change your process of coming up with the logic that you put inside the if statement. Here is a description of how you could build it up.
First, start with the condition that you're considering "good". The "good" condition is "$subd is one of 'www' or 'nosub'". The if statement for this would be: if ($subd == 'www' || $subd == 'nosub')
Now, you're trying to write code to handle the condition not being good, so you need to take the opposite of the good condition. To take the opposite of a boolean condition, you surround the whole thing with a NOT. In code: if !($subd == 'www' || $subd == 'nosub')
(note the exclamation point in front).
If you want to move that negation inside (as you had been trying to do originally), it's a property of boolean algebra (I hope this is the right term, it's been a long time since I learned this) that when you move a negation into a relation like that, you negate both the operands, and also change the operator from an AND to an OR, or vice versa. So in this case, when you move the negative inside the parentheses, both the ==
become !=
and the ||
becomes &&
, resulting in: if ($subd != 'www' && $subd != 'nosub)
, as I had given above.
Edit again: The properties I mention in the last paragraph are called De Morgan's laws.