0

The code below is the main index page of my website. It's working perfectly fine on my test server--redirecting me to the login page if I'm not logged in, or if any session is not set. However, I uploaded it to my live server--it's working fine there as well, until I change the url from index.php?X=0&Y=0 to index.php. At which point it only shows a the background and nothing else.

Everything was working fine on both ends until earlier today when I reuploaded everything to my server, but none of the code has changed so nothing should be different, but it is. So, I wondering if you guys see anything that could be causing it.

There are no errors, the page just doesn't load properly.

<?php //* Something Wicked This Way Comes *//
require_once("lib/bootstrap.php");
$html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'.
        '<html xmlns="http://www.w3.org/1999/xhtml">'.
        '<head>'.
        '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'.
        '<meta name="description" content="Control the Universe!"/>'.
        '<meta name="keywords" content="game,web based, reddact, arg, story, gmz1023,elements" />'.
        '<title>Reddact</title>'.
        '<link rel="stylesheet" href="assets/style.css" />'.
        '<link rel="stylesheet" type="text/css" href="assets/css/tooltipster.css" />'.
        '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>'.
        '<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>'.
        '<script src="js/jquery.tooltipster.min.js" type="text/javascript"></script>'.
        '<script src="js/TimeCircles.js" type="text/javascript"></script>'.
        '<script src="js/jquery.validate.min.js"></script>'.
        '<script src="js/js.js" type="text/javascript"></script>'.
        '<link href="favicon.ico" rel="icon" type="image/x-icon" />'.
        '<link rel="stylesheet" href="js/TimeCircles.css" />'.
        '</head>'.

        '<body>';
    echo $html;
if(!isset($_SESSION))
{
include('parts/login-page.php');
}
if(!isset($_SESSION['uid']))
{
    if(!isset($_GET['error']))
    {
        include('parts/login-page.php');
    }
    else
    {
        include('parts/login-page.php');
    }
}
if(isset($_SESSION['uid']))
{

        if(isset($_GET['mode']))
        {
            $file = 'parts/active/'.$_GET['mode'].'.php';
            if(file_exists($file))
            {
                include($file);
            }
            else
            {
                include('404.html');
            }
        }
        else
        {
            if(!isset($_GET['X']) && !isset($_GET['Y']))
            {
                header('Location:'.$_SESSION['index']); 
            }
            else
            {
                if(isset($_GET['portal']))
                {
                    include('first_time.php');  
                }
                else
                {
                include('starmap.php');
                include('nav-menu.php');
                }

            }
?>
</div>
</body>
</html>
<?php
        }
}
?>
user3462020
  • 63
  • 1
  • 7

2 Answers2

2

This block:

        if(!isset($_GET['X']) && !isset($_GET['Y']))
        {
            header('Location:'.$_SESSION['index']); 
        }

is the problem. You cannot change the header after outputting anything. It will often not be caught on localhost, but will most certainly not work on a live server.

Try putting echo $html; somewhere below the series of if-else statements.

Mark Miller
  • 7,442
  • 2
  • 16
  • 22
0
<?php
html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'.
    '<html xmlns="http://www.w3.org/1999/xhtml">'.
    '<head>'.
    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'.
    '<meta name="description" content="Control the Universe!"/>'.
    '<meta name="keywords" content="game,web based, reddact, arg, story, gmz1023,elements" />'.
    '<title>Reddact</title>'.
    '<link rel="stylesheet" href="assets/style.css" />'.
    '<link rel="stylesheet" type="text/css" href="assets/css/tooltipster.css" />'.
    '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>'.
    '<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>'.
    '<script src="js/jquery.tooltipster.min.js" type="text/javascript"></script>'.
    '<script src="js/TimeCircles.js" type="text/javascript"></script>'.
    '<script src="js/jquery.validate.min.js"></script>'.
    '<script src="js/js.js" type="text/javascript"></script>'.
    '<link href="favicon.ico" rel="icon" type="image/x-icon" />'.
    '<link rel="stylesheet" href="js/TimeCircles.css" />'.
    '</head>'.

    '<body>';
echo $html;

and then after some code you say:

 header('Location:'.$_SESSION['index']); 

answer is: Headers already sent error Headers must be set BEFORE any html content is shown

so first: header

then echo the html

also check if your index.php?X=0&Y=0 works if not (I assume here is the redirect) if so it's logically your php.ini doesn't show errors because display_errors is probably on 0 also like I said above here first sending the headers (html) and after that modify the header (header()) is not allowed.

so what you want to do is putting that whole redirect if statement above the echo $html; and you should be fine...

Mike M.
  • 361
  • 2
  • 14
  • That did it. I must've switched around my code without realizing it. Thank you very much, sir, you are a scholar and a gentlemen for pointing out my novice mistake. – user3462020 May 06 '14 at 06:41
  • well it's a regular mistake. sometimes I also forget just to switch it to an upper level but ye it's normal. http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php/8028987#8028987 would help you to get known with why the header() error/issue keeps popping up. – Mike M. May 06 '14 at 06:42