-2

So i've got a rather complex bit of code that i'm trying to make work (actually; it works fine on my test server but not so much my live server. so i'm trying to make it rework) -- it keeps telling me that a variable i'm asking it to check with isset is not a defined variable. I'm probably over thinking this whole method and there's probably a simplier way. but i need you guys to bash me over the head with it apparently

include('bootstra.php');
include('includes/parts/head.php');
if(!isset($_SESSION['user']['uid']))
{
    echo $html;
    include('includes/parts/login.php');
    if(isset($_GET['mode']))
    {
        $file = $_GET['mode'];
        $path = "includes/parts/{$file}.php";
        if (file_exists($path)) {
            require_once($path);
        } else {
            die("The Page REquested could not be found!");
        }
    }
    else
    {   
        include('includes/parts/frontpage.php');
    }
}
else
{
    if(!isset($_SESSION['x']) || !isset($_SESSION['y']))
    {
        if(isset($_GET['x']) && isset($_GET['y']))
        {
            $_SESSION['x'] = $_GET['x'];
            $_SESSION['y'] = $_GET['y'];
        }
        else
        {
        $_SESSION['x'] = 0;
        $_SESSION['y'] = 0;
        }
        header("location:index.php?x={$_SESSION['x']}&y={$_SESSION['y']}");
    }
    else
    {
        if($_SESSION['x'] != $_GET['x'] || $_SESSION['y'] != $_GET['y'] )
        {
            header("location:index.php?x={$_SESSION['x']}&y={$_SESSION['y']}");     
        }
        else
        {   
            echo $html;
            echo $base->displayMap($_GET['x'], $_GET['y']); 
            include('includes/context_menu.php');
        }
    }
}

Here is the exact error:
Notice: Undefined index: x in /home/****/public_html/reddactgame/index.php on line 27

user3462020
  • 63
  • 1
  • 7

2 Answers2

0

Change it

<pre>
     if( !isset($_SESSION['x']) || !isset($_SESSION['y']) )
</pre>

to

<pre>
    if( !( isset($_SESSION['x']) && isset($_SESSION['y']) ) )
</pre>
0

There is no error, that is a Warning...

It is saying that $_SESSION['x'] was never setted, so, when you do that isset it tells you that it was never declared.


Example:

This gives you the same warning

empty($x);


This does not give you warning

$x = 0;
empty($x);

EDIT

I see this is a common question, so here is a better explanation.

Community
  • 1
  • 1
matiaslauriti
  • 7,065
  • 4
  • 31
  • 43