W D W D - 7 months ago 57
PHP Question

PHP IF / OR Not Working

I'm setting up a small magazine with several sections that all work from the same PHP page.

I'd like it to redirect people back to the home page if they are not on an official section. So for this my code is:

if (isset($_GET["section"])) {
$section = $_GET["section"];
} else {
header("Location: $site_url");

if ($section !== 'gallery' || $section !== 'magazine' || $section !== 'picks' || $section !== 'customs' || $section !== 'editor') {
header("Location: $site_url");

The problem is, when I visit
, I'm redirected back to the home page, even though it is in the If statement. Anyone know why this is?


This will always be true:

$section !== 'gallery' || $section !== 'magazine' || ...

Because the same variable can never simultaneously be more than one value. I suspect you meant to use &&:

$section !== 'gallery' && $section !== 'magazine' && ...