我的解决办法只有,把header提前。或:echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=index.php\">",用include行吗?

解决方案 »

  1.   

    “解决”的意思是不是怎样避免这种错误吧?
    用headers_sent()判断
      

  2.   

    估计出题的意思是不是让你设计个流程,使重定向时不会有错语信息?
    用意在考查你会不会用headers_sent这个函数?
    <?
    if (!headers_sent()) {
        header ('Location: http://www.example.com/');
        exit; } 
    else {
        echo "<script>window.location =\"$PHP_SELF\";</script>"; 
        exit;
    }
    ?>
      

  3.   

    重定向可以用以下方法实现,不过它是用JS不是PHP
    echo "<script>top.location.href='$to';</script>";
    它可以随时使用。
      

  4.   

    <?php
    ob_start(); 
    echo "xxxx";
    header("Location: index.php"); 
    ob_end_flush(); 
    ?>应回答:输出控制函数