isset $ _GET没有显示正确的信息

时间:2016-02-23 13:46:40

标签: php get isset

我的代码不起作用

<?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;
}
?>

当我去

  

localhost / directory /或localhost / directory /?page =

显示主页 但是当我去

  

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

显示404页面

2 个答案:

答案 0 :(得分:0)

您正在将isset($_GET['page'])"value"进行比较。 isset返回true / false,因此您希望将$_GET['page']变量与"value"进行比较,而不是将其设置。

因此,您的elseif语句应如下所示:

elseif($_GET['page'] === "hypixel")
{
include 'includes/view/hypixelapi.php';
echo $index;
}

答案 1 :(得分:0)

您将使用isset()函数来分配不应该出现的变量:

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

如果设置了true,则会返回$_GET['page']

从字面意义isset()表示变量已设置。它是BOOL函数,这意味着它只能在设置时返回true,在未设置/空时返回false

因此,您的代码应为:

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

==用于比较,而===是否相同,更多信息位于The 3 different equals

有关isset()的更多信息:http://php.net/manual/en/function.isset.php