dslfq06464 2017-04-07 16:20 采纳率: 0%
浏览 40
已采纳

无法修改标头信息错误? [重复]

This question already has an answer here:

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>
</div>
  • 写回答

2条回答 默认 最新

  • douwen5066 2017-04-07 16:23
    关注

    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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划