-1

IK this is prob a dupe, but I cant find any solutions to my code what so ever, no matter what code i add/change, it just wont budge... (NOTE im not using normal php, using a friends version, which yes, is fine and dandy)

<?php
include($_SERVER['DOCUMENT_ROOT'].'/phpAlphaDB/core.php');
?>

<html>
<head>
<link rel="icon" type="image/png" href="../logo.png">
    <title> Xenoz Web - Users </title>
    <link rel="stylesheet" type="text/css" href="../css/style.php" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<?php
    if ($role==0) {
    header('Location: http://xenozweb.tk/index.php');
} else {
        echo '<script>alert("Hello, '.$username.'. Welcome to the userlist...");</script>';
    }
    ?>

<body>
    <div class="navigation">
        <a href="index.php"><div class="navitem"> Home </div></a>      
        <a href="/register/"><div class="navitem"> Register </div></a>
        <a href="/login/"><div class="navitem"> Login </div></a>
        <a href="/users/"><div class="navitem"> Users </div></a>
        <a href="/jukebox/"><div class="navitem"> Jukebox </div></a>
        </div>
    </div>
    <div class="pagecontent">
       <div class="userblock">
        <?php
          $results = db_read('xenozweb-users', '',  'username');
          foreach ($results as $result) {
          $u_name = db_column($result, 0);
          echo '<div class="users">',$u_name,'</div>';
          }
            ?>
        </div>
    </div>
</body>
</html>
n0b0y
  • 3
  • 3
  • No output can occur before header as listed in [PHP: header](https://secure.php.net/manual/en/function.header.php) – FD3 Apr 07 '17 at 16:23

2 Answers2

0

You're returning a partial response before you set the header. Headers must be sent before a response is sent back to the browser.

Try moving the header('Location: ') function call into the top <?php enclosure like so:

<?php
    include($_SERVER['DOCUMENT_ROOT'].'/phpAlphaDB/core.php');

    if ($role==0) {
        header('Location: http://xenozweb.tk/index.php');
    }
?>

<html>
<head>
<link rel="icon" type="image/png" href="../logo.png">
<title> Xenoz Web - Users </title>
<link rel="stylesheet" type="text/css" href="../css/style.php" />
<meta http-equiv="content-type" content="text/html; charset=utf-8">

<?php
     if ($role != 0) {
        echo '<script>alert("Hello, '.$username.'. Welcome to the userlist...");</script>';
    }
?>

</head>
<body>
Andrew Burns
  • 324
  • 4
  • 10
0

You've already sent data to the browser. you cannot send header() info properly once you've already started to send data payload.

Anthony Gray
  • 344
  • 4
  • 7