0

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:

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

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

The problem is, when I visit localhost/results.php?section=gallery, I'm redirected back to the home page, even though it is in the If statement. Anyone know why this is?

paolobasso
  • 2,008
  • 12
  • 25
W D
  • 105
  • 3
  • 9

1 Answers1

1

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' && ...
David
  • 208,112
  • 36
  • 198
  • 279