You need to do every comparison completely, like this:
if($_SERVER['REQUEST_URI'] == 'index' || $_SERVER['REQUEST_URI'] == 'post' || $_SERVER['REQUEST_URI'] == 'about'){
// why this not work for me?
}
Since, what you're doing now, is comparing $_SERVER["REQUEST_URI"]
to true
:
var_dump("hello" || "index"); // bool(true)
So the comparison is always true, because you're using only two equal signs, which is a loose comparison. Had you used ===
, the result would be false because a string
is not of the same type as a boolean
.
Another way is to use an array and in_array()
, which will check if a value is in the values of an array:
$values = ["index", "post", "about"];
if (in_array($_SERVER["REQUEST_URI"], $values)) {