无法修改标头信息错误?

时间:2017-04-07 16:20:17

标签: php

IK这可能是一个骗局,但我无法找到任何解决方案,所以,无论我添加/更改什么代码,它只是不会让步......(注意我不使用普通的PHP,使用朋友版本,是的,很好,花花公子)

<?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>

2 个答案:

答案 0 :(得分:0)

您在设置标头之前返回部分响应。必须在将响应发送回浏览器之前发送标头。

尝试将header('Location: ')函数调用移到顶部<?php附件中,如下所示:

<?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>

答案 1 :(得分:0)

您已将数据发送到浏览器。一旦您已经开始发送数据有效负载,就无法正确发送header()信息。