Reputation:
I have sth like this:
<?php
$body = $_GET["body"];
if ($body=="")
{
include("includes/desktop.php");
}
else
{
if (is_file("includes/$body.php"))
{
include("includes/$body.php");
}
else
{
include("includes/desktop.php");
}
}
?>
How to make that this notice will disappear? It happens only when $_GET["body"] is empty.
Notice: Undefined index: body in C:\wamp\www\admin\index.php on line 106
Upvotes: 1
Views: 748
Reputation: 6120
It is warning you that body is not sent via $_GET. You need to do something like this
<?php
if (isset($_GET["body"])) {
$body = $_GET["body"];
if ($body=="")
{
include("includes/desktop.php");
}
else
{
if (is_file("includes/$body.php"))
{
include("includes/$body.php");
}
else
{
include("includes/desktop.php");
}
}
}
?>
Upvotes: 0
Reputation: 6182
change
$body = $_GET["body"];
To
$body = isset($_GET["body"]) ? $_GET["body"] : '';
You can find almost all symbols and operators in php here
Upvotes: 1
Reputation: 793
Try
if (!isset($_GET['body']) || empty($_GET['body'])) {
include("includes/desktop.php");
} else {
...
}
On a side note: You should never trust user input. Directly passing the body GET parameter to your include() call allows a malicious user to include files you never intended to load.
Upvotes: 0
Reputation: 34566
It's happening because there is no index body
in the superglobal $_GET
array. In other words, you're not passing $_GET['body']
.
Instead use:
if (isset($_GET['body']) && $_GET['body']) {
That checks for both the index and a meaningful (non-falsy) value.
Upvotes: 0