0
votes

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

4

4 Answers

1
votes

change

$body = $_GET["body"];

To

$body = isset($_GET["body"]) ? $_GET["body"] : '';

You can find almost all symbols and operators in php here

0
votes

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.

0
votes

Try

if (!isset($_GET['body']) || empty($_GET['body'])) {
   include("includes/desktop.php");
} else {
    ...
}

http://www.php.net/isset

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.

0
votes

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