dslfq06464 2017-04-07 08: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 08: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部