0

My code below doesnt work

<?php 
//Laat homepage zien als het leeg is
if(!isset($_GET['page']))
{
include 'includes/view/homepage.php';
echo $index;
}
elseif(empty($_GET["page"]))
{
include 'includes/view/homepage.php';
echo $index;
}
//Laat uitleg zien van hypixel api
elseif(isset($_GET['page']) === "hypixel")
{
include 'includes/view/hypixelapi.php';
echo $index;
}
//Laat errors zien die je kan krijgen
elseif(isset($_GET['page']) === "errors")
{
include 'includes/view/errors.php';
echo $index;
}
//Laat player api uitleg zien
elseif(isset($_GET['page']) === "player")
{
include 'includes/view/playerapi.php';
echo $index;
}
//Laat server api uitleg zien
elseif(isset($_GET['page']) === "server")
{
include 'includes/view/serverapi.php';
echo $index;
}
//Laat error 404 zien als het fout is
else
{
include 'includes/errors/404.php';
echo $index;
}
?>

When i go to

localhost/directory/ or localhost/directory/?page=

It shows the homepage but when i go to

localhost/directory/?page=errors or localhost/directory/?page=hypixel

It shows the 404 page

  • 3
    `isset` return `bool`. You should compare this way: `elseif ($_GET['page'] === "hypixel")`. – brevis Feb 23 '16 at 13:49

2 Answers2

0

You are comparing isset($_GET['page'])to "value". isset returns true/false, so you want to compare $_GET['page'] variable to "value", not if it is set.

So your elseif statement should look like this:

elseif($_GET['page'] === "hypixel")
{
include 'includes/view/hypixelapi.php';
echo $index;
}
Thomas Orlita
  • 1,554
  • 14
  • 28
0

You'll using isset() function to assign variables which should not be the case:

isset($_GET['page']) === "player"

This will return true if $_GET['page'] is set.

As from the literal meaning isset() means variable is set. It's a BOOL function, which means that it can only return true when set and false when not set/ empty.

Thus, your code should be:

$_GET['page'] == "player"

== is for comparison, while === is whether it's identical, more information at The 3 different equals.

More information on isset(): http://php.net/manual/en/function.isset.php.

Community
  • 1
  • 1
Panda
  • 6,955
  • 6
  • 40
  • 55