douchuoxuan3177 2012-09-12 21:56
浏览 17
已采纳

已发送的标题,找不到问题[重复]

Possible Duplicate:
Headers already sent by PHP

Ok, so I made a script that has an admin panel, and all was working well. I moved servers and now the code breaks. i've been googling all day and there are no spaces before any opening/closing php tags, i have ob_start(); & ob_end_flush(); before and after the session_start() and yet i'm still getting errors. Can anyone find where ive gone wrong?

<?php
    ob_start();
    $host="localhost"; // Host name
    $username=""; // Mysql username
    $password=""; // Mysql password
    $db_name=""; // Database name 
    $tbl_name=""; // Table name
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    $ref = null;
    if ($_POST['ref'])
    {
$ref = $_POST['ref'];
    }
    $myusername=$_POST['username'];
    $mypassword=$_POST['password'];
    $myusername = stripslashes(mysql_real_escape_string($myusername));
    $mypassword = stripslashes(mysql_real_escape_string($mypassword));
    $sql="SELECT * FROM `$tbl_name` WHERE `username`='$myusername' and           `password`='$mypassword'";
    $result=mysql_query($sql);
    $count=mysql_num_rows($result);
    if($count==1){
    $dt2=date("Y-m-d H:i:s");
function getip()
{
    $ip = null;
        if (isset($_SERVER["REMOTE_ADDR"])){$ip = $_SERVER["REMOTE_ADDR"];} 
        else if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){$ip =     $_SERVER["HTTP_X_FORWARDED_FOR"];}
        else if (isset($_SERVER["HTTP_CLIENT_IP"])){$ip =   $_SERVER["HTTP_CLIENT_IP"];}
    return $ip;
}
$myperms = null;
while ($row = mysql_fetch_array($result)) {
    $myperms = $row['perms'];
    }
     mysql_query("UPDATE admins SET `lastlogin`='".$dt2."',`lastip`='".getip()."', state='1' WHERE username='".$myusername."'"); 
     mysql_query("UPDATE settings SET `lastadmin`='".$myusername."',`lastadminip`='".getip()."'"); 
    session_start();
    $_SESSION['username'] = $myusername;
    $_SESSION['permissions'] = $myperms;
    if ($ref)
    {
    header("location:admin.php?list=".$ref);
    }
    else
    {
    header("location:admin.php");
    }
    }
    else {
    echo "Wrong Username or Password";
    }
    ob_end_flush();
    ?>

I keep getting 2 errors (home directory path nulled out):

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at admin/checklogin.php:1) in admin/checklogin.php on line 47

and

    Warning: Cannot modify header information - headers already sent by (output started at admin/checklogin.php:1) in admin/checklogin.php on line 56

I can't figure out why it does this on the new server but not the old. Another post on google said "some hosts dont like html before the header is sent" but i don't have any html in this file so im still at a loss. any ideas?

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dougaicha5258 2012-09-12 21:57
    关注

    Even here in your question I see spaces before <?php. Anything before <?php is treated as an output, and you shouldn't have anything sent before you send headers

    If 4 spaces before <?php is not the case - look for the BOM character in the file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?