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 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退